diff options
author | David Walter Seikel | 2012-02-04 10:39:45 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-02-04 10:39:45 +1000 |
commit | f38cf6882a1517a5a913c6a50f8c3d34578a478b (patch) | |
tree | 9350bcf150d9d7564f0bd8adf1f4a12f787a6655 | |
parent | Make states actually work. (diff) | |
download | SledjHamr-f38cf6882a1517a5a913c6a50f8c3d34578a478b.zip SledjHamr-f38cf6882a1517a5a913c6a50f8c3d34578a478b.tar.gz SledjHamr-f38cf6882a1517a5a913c6a50f8c3d34578a478b.tar.bz2 SledjHamr-f38cf6882a1517a5a913c6a50f8c3d34578a478b.tar.xz |
Prepend all our generated names with an underscore, might help stop name polution.
-rw-r--r-- | LuaSL/src/LuaSL_compile.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index fe401c8..cef6713 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c | |||
@@ -1842,7 +1842,7 @@ static void outputRawStatement(FILE *file, outputMode mode, LSL_Statement *state | |||
1842 | } | 1842 | } |
1843 | else if (OM_LUA == mode) | 1843 | else if (OM_LUA == mode) |
1844 | { | 1844 | { |
1845 | fprintf(file, "stateChange("); | 1845 | fprintf(file, "stateChange(_"); |
1846 | if (statement->identifier.text) | 1846 | if (statement->identifier.text) |
1847 | outputText(file, &(statement->identifier), TRUE); | 1847 | outputText(file, &(statement->identifier), TRUE); |
1848 | fprintf(file, "State)"); | 1848 | fprintf(file, "State)"); |
@@ -1946,10 +1946,10 @@ static void outputRawStatement(FILE *file, outputMode mode, LSL_Statement *state | |||
1946 | 1946 | ||
1947 | // if ((MF_PREDEC | MF_PREINC | MF_POSTDEC | MF_POSTINC) & statement->flags) | 1947 | // if ((MF_PREDEC | MF_PREINC | MF_POSTDEC | MF_POSTINC) & statement->flags) |
1948 | // fprintf(file, "\n"); | 1948 | // fprintf(file, "\n"); |
1949 | if (MF_PREDEC & statement->flags) fprintf(file, "local function preDecrement_%s() %s = %s - 1; return %s; end\n", name, name, name, name); | 1949 | if (MF_PREDEC & statement->flags) fprintf(file, "local function _preDecrement_%s() %s = %s - 1; return %s; end\n", name, name, name, name); |
1950 | if (MF_PREINC & statement->flags) fprintf(file, "local function preIncrement_%s() %s = %s + 1; return %s; end\n", name, name, name, name); | 1950 | if (MF_PREINC & statement->flags) fprintf(file, "local function _preIncrement_%s() %s = %s + 1; return %s; end\n", name, name, name, name); |
1951 | if (MF_POSTDEC & statement->flags) fprintf(file, "local function postDecrement_%s() local temp = %s; %s = %s - 1; return temp; end\n", name, name, name, name); | 1951 | if (MF_POSTDEC & statement->flags) fprintf(file, "local function _postDecrement_%s() local _temp = %s; %s = %s - 1; return _temp; end\n", name, name, name, name); |
1952 | if (MF_POSTINC & statement->flags) fprintf(file, "local function postDecrement_%s() local temp = %s; %s = %s + 1; return temp; end\n", name, name, name, name); | 1952 | if (MF_POSTINC & statement->flags) fprintf(file, "local function _postDecrement_%s() local _temp = %s; %s = %s + 1; return _temp; end\n", name, name, name, name); |
1953 | } | 1953 | } |
1954 | 1954 | ||
1955 | if (statement->elseBlock) | 1955 | if (statement->elseBlock) |
@@ -1970,12 +1970,12 @@ bit.band(swap= --[[(integer)]] ( --[[(string)]] pkey), 1) ; | |||
1970 | 1970 | ||
1971 | switch (leaf->toKen->type) | 1971 | switch (leaf->toKen->type) |
1972 | { | 1972 | { |
1973 | case LSL_BIT_AND : fprintf(file, " bit.band("); break; | 1973 | case LSL_BIT_AND : fprintf(file, " _bit.band("); break; |
1974 | case LSL_BIT_OR : fprintf(file, " bit.bor("); break; | 1974 | case LSL_BIT_OR : fprintf(file, " _bit.bor("); break; |
1975 | case LSL_BIT_XOR : fprintf(file, " bit.xor("); break; | 1975 | case LSL_BIT_XOR : fprintf(file, " _bit.xor("); break; |
1976 | case LSL_BIT_NOT : fprintf(file, " bit.bnot("); break; | 1976 | case LSL_BIT_NOT : fprintf(file, " _bit.bnot("); break; |
1977 | case LSL_LEFT_SHIFT : fprintf(file, " bit.lshift("); break; | 1977 | case LSL_LEFT_SHIFT : fprintf(file, " _bit.lshift("); break; |
1978 | case LSL_RIGHT_SHIFT : fprintf(file, " bit.rshift("); break; | 1978 | case LSL_RIGHT_SHIFT : fprintf(file, " _bit.rshift("); break; |
1979 | default : break; | 1979 | default : break; |
1980 | } | 1980 | } |
1981 | outputLeaf(file, mode, leaf->left); | 1981 | outputLeaf(file, mode, leaf->left); |
@@ -2032,10 +2032,10 @@ static void outputCrementsToken(FILE *file, outputMode mode, LSL_Leaf *content) | |||
2032 | { | 2032 | { |
2033 | switch (content->toKen->type) | 2033 | switch (content->toKen->type) |
2034 | { | 2034 | { |
2035 | case LSL_DECREMENT_PRE : fprintf(file, " preDecrement"); break; | 2035 | case LSL_DECREMENT_PRE : fprintf(file, " _preDecrement"); break; |
2036 | case LSL_INCREMENT_PRE : fprintf(file, " preIncrement"); break; | 2036 | case LSL_INCREMENT_PRE : fprintf(file, " _preIncrement"); break; |
2037 | case LSL_DECREMENT_POST : fprintf(file, " postDecrement"); break; | 2037 | case LSL_DECREMENT_POST : fprintf(file, " _postDecrement"); break; |
2038 | case LSL_INCREMENT_POST : fprintf(file, " postIncrement"); break; | 2038 | case LSL_INCREMENT_POST : fprintf(file, " _postIncrement"); break; |
2039 | default : | 2039 | default : |
2040 | break; | 2040 | break; |
2041 | } | 2041 | } |
@@ -2094,7 +2094,7 @@ static void outputFunctionToken(FILE *file, outputMode mode, LSL_Leaf *content) | |||
2094 | else if (OM_LUA == mode) | 2094 | else if (OM_LUA == mode) |
2095 | { | 2095 | { |
2096 | if (func->state) | 2096 | if (func->state) |
2097 | fprintf(file, "\n\n%sState.%s = function(", func->state, func->name.text); | 2097 | fprintf(file, "\n\n_%sState.%s = function(", func->state, func->name.text); |
2098 | else | 2098 | else |
2099 | { | 2099 | { |
2100 | fprintf(file, "\n\nfunction "); | 2100 | fprintf(file, "\n\nfunction "); |
@@ -2267,7 +2267,7 @@ static void outputStateToken(FILE *file, outputMode mode, LSL_Leaf *content) | |||
2267 | } | 2267 | } |
2268 | else if (OM_LUA == mode) | 2268 | else if (OM_LUA == mode) |
2269 | { | 2269 | { |
2270 | fprintf(file, "\n\n--[[state]] "); | 2270 | fprintf(file, "\n\n--[[state]] _"); |
2271 | outputText(file, &(state->name), !(LSL_NOIGNORE & content->toKen->flags)); | 2271 | outputText(file, &(state->name), !(LSL_NOIGNORE & content->toKen->flags)); |
2272 | fprintf(file, "State = {};"); | 2272 | fprintf(file, "State = {};"); |
2273 | outputRawBlock(file, mode, state->block, FALSE); | 2273 | outputRawBlock(file, mode, state->block, FALSE); |
@@ -2335,16 +2335,16 @@ static boolean doneParsing(LuaSL_compiler *compiler) | |||
2335 | if (out) | 2335 | if (out) |
2336 | { | 2336 | { |
2337 | fprintf(out, "--// Pre declared helper stuff.\n"); | 2337 | fprintf(out, "--// Pre declared helper stuff.\n"); |
2338 | fprintf(out, "local bit = require(\"bit\")\n"); | 2338 | fprintf(out, "local _bit = require(\"bit\")\n"); |
2339 | fprintf(out, "currentState = {}\n"); | 2339 | fprintf(out, "_currentState = {}\n"); |
2340 | fprintf(out, "function preDecrement(name) _G[name] = _G[name] - 1; return _G[name]; end;\n"); | 2340 | fprintf(out, "function _preDecrement(name) _G[name] = _G[name] - 1; return _G[name]; end;\n"); |
2341 | fprintf(out, "function preIncrement(name) _G[name] = _G[name] + 1; return _G[name]; end;\n"); | 2341 | fprintf(out, "function _preIncrement(name) _G[name] = _G[name] + 1; return _G[name]; end;\n"); |
2342 | fprintf(out, "function postDecrement(name) local temp = _G[name]; _G[name] = _G[name] - 1; return temp; end;\n"); | 2342 | fprintf(out, "function _postDecrement(name) local temp = _G[name]; _G[name] = _G[name] - 1; return temp; end;\n"); |
2343 | fprintf(out, "function postIncrement(name) local temp = _G[name]; _G[name] = _G[name] + 1; return temp; end;\n"); | 2343 | fprintf(out, "function _postIncrement(name) local temp = _G[name]; _G[name] = _G[name] + 1; return temp; end;\n"); |
2344 | fprintf(out, "function stateChange(x) if nil ~= currentState.state_exit then currentState.state_exit(); end currentState = x; if nil ~= currentState.state_entry then currentState.state_entry(); end end;\n"); | 2344 | fprintf(out, "function _stateChange(x) if nil ~= _currentState.state_exit then _currentState.state_exit(); end _currentState = x; if nil ~= _currentState.state_entry then _currentState.state_entry(); end end;\n"); |
2345 | fprintf(out, "--// Generated code goes here.\n\n"); | 2345 | fprintf(out, "--// Generated code goes here.\n\n"); |
2346 | outputLeaf(out, OM_LUA, compiler->ast); | 2346 | outputLeaf(out, OM_LUA, compiler->ast); |
2347 | fprintf(out, "\n\n--stateChange(defaultState)\n"); // This actually starts the script running. Not ready for that yet, gotta implement some ll*() functions first. So commented it out in Lua. | 2347 | fprintf(out, "\n\n--_stateChange(_defaultState)\n"); // This actually starts the script running. Not ready for that yet, gotta implement some ll*() functions first. So commented it out in Lua. |
2348 | fprintf(out, "\n--// End of generated code.\n\n"); | 2348 | fprintf(out, "\n--// End of generated code.\n\n"); |
2349 | fclose(out); | 2349 | fclose(out); |
2350 | sprintf(buffer, "../../libraries/luajit-2.0/src/luajit \"%s\"", luaName); | 2350 | sprintf(buffer, "../../libraries/luajit-2.0/src/luajit \"%s\"", luaName); |