diff options
author | David Walter Seikel | 2012-02-04 20:49:07 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-02-04 20:49:07 +1000 |
commit | 02d2afee7e161f69e38900e60f191186262cbb8c (patch) | |
tree | 2ab46040fb0376e1909ce6749219d410f20729cb /LuaSL | |
parent | Add LSL.lua module, with the constants and functions in it. Functions are ju... (diff) | |
download | SledjHamr-02d2afee7e161f69e38900e60f191186262cbb8c.zip SledjHamr-02d2afee7e161f69e38900e60f191186262cbb8c.tar.gz SledjHamr-02d2afee7e161f69e38900e60f191186262cbb8c.tar.bz2 SledjHamr-02d2afee7e161f69e38900e60f191186262cbb8c.tar.xz |
Move the predefined Lua stuff into the new LSL.lua module, then actualy use it.
Diffstat (limited to 'LuaSL')
-rw-r--r-- | LuaSL/src/LSL.lua | 25 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_compile.c | 22 |
2 files changed, 30 insertions, 17 deletions
diff --git a/LuaSL/src/LSL.lua b/LuaSL/src/LSL.lua index 7557668..cc9b454 100644 --- a/LuaSL/src/LSL.lua +++ b/LuaSL/src/LSL.lua | |||
@@ -1,12 +1,15 @@ | |||
1 | -- A module of LSL stuffs. | 1 | -- A module of LSL stuffs. |
2 | -- TODO - currently there is a constants.lsl file. Move it into here. | 2 | -- TODO - currently there is a constants.lsl file. Move it into here. |
3 | -- It contains LSL constants and ll*() functions stubs. | 3 | -- It contains LSL constants and ll*() functions stubs. |
4 | -- The compiler compiles this into a LSL_Scripts structure at startup, | 4 | -- The compiler compiles that into a LSL_Scripts structure at startup, |
5 | -- then uses that for function and variable lookups, as well as looking up in the current script. | 5 | -- then uses that for function and variable lookups, as well as looking up in the current script. |
6 | -- Using a module means it gets compiled each time? Maybe not if I can use bytecode files. Perhaps LuaJIT caches these? | 6 | -- I can run this at compiler startup time, then iterate through the LSL table from C to generate that LSL_Script structure. |
7 | |||
8 | -- Using a module means it gets compiled each time? Maybe not if I can use bytecode files. Perhaps LuaJIT caches these? | ||
9 | -- Does not seem to be slowing it down noticably, but that might change once the stubs are filled out. | ||
7 | 10 | ||
8 | -- Use it like this - | 11 | -- Use it like this - |
9 | -- local lsl = require 'lsl' | 12 | -- local _LSL = require 'LSL' |
10 | 13 | ||
11 | --[[ From http://lua-users.org/wiki/LuaModuleFunctionCritiqued | 14 | --[[ From http://lua-users.org/wiki/LuaModuleFunctionCritiqued |
12 | A related note on C code: The luaL_register [9] function in C is | 15 | A related note on C code: The luaL_register [9] function in C is |
@@ -292,6 +295,22 @@ function LSL.llWhisper(--[[integer]] channel, --[[string]] text) end; | |||
292 | 295 | ||
293 | function LSL.llMessageLinked(--[[integer]] link,--[[integer]] num, --[[string]] text, --[[key]] aKey) end; | 296 | function LSL.llMessageLinked(--[[integer]] link,--[[integer]] num, --[[string]] text, --[[key]] aKey) end; |
294 | 297 | ||
298 | function LSL.preDecrement(name) _G[name] = _G[name] - 1; return _G[name]; end; | ||
299 | function LSL.preIncrement(name) _G[name] = _G[name] + 1; return _G[name]; end; | ||
300 | function LSL.postDecrement(name) local temp = _G[name]; _G[name] = _G[name] - 1; return temp; end; | ||
301 | function LSL.postIncrement(name) local temp = _G[name]; _G[name] = _G[name] + 1; return temp; end; | ||
302 | |||
303 | local currentState = {} | ||
304 | function LSL.stateChange(x) | ||
305 | if nil ~= currentState.state_exit then | ||
306 | currentState.state_exit(); | ||
307 | end | ||
308 | currentState = x; | ||
309 | if nil ~= currentState.state_entry then | ||
310 | currentState.state_entry(); | ||
311 | end | ||
312 | end; | ||
313 | |||
295 | 314 | ||
296 | return LSL; | 315 | return LSL; |
297 | 316 | ||
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index f997d62..7fa7cd7 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c | |||
@@ -1931,7 +1931,7 @@ static void outputRawStatement(FILE *file, outputMode mode, LSL_Statement *state | |||
1931 | } | 1931 | } |
1932 | else if (OM_LUA == mode) | 1932 | else if (OM_LUA == mode) |
1933 | { | 1933 | { |
1934 | fprintf(file, "stateChange(_"); | 1934 | fprintf(file, "_LSL.stateChange(_"); |
1935 | if (statement->identifier.text) | 1935 | if (statement->identifier.text) |
1936 | outputText(file, &(statement->identifier), TRUE); | 1936 | outputText(file, &(statement->identifier), TRUE); |
1937 | fprintf(file, "State)"); | 1937 | fprintf(file, "State)"); |
@@ -2121,10 +2121,10 @@ static void outputCrementsToken(FILE *file, outputMode mode, LSL_Leaf *content) | |||
2121 | { | 2121 | { |
2122 | switch (content->toKen->type) | 2122 | switch (content->toKen->type) |
2123 | { | 2123 | { |
2124 | case LSL_DECREMENT_PRE : fprintf(file, " _preDecrement"); break; | 2124 | case LSL_DECREMENT_PRE : fprintf(file, " _LSL.preDecrement"); break; |
2125 | case LSL_INCREMENT_PRE : fprintf(file, " _preIncrement"); break; | 2125 | case LSL_INCREMENT_PRE : fprintf(file, " _LSL.preIncrement"); break; |
2126 | case LSL_DECREMENT_POST : fprintf(file, " _postDecrement"); break; | 2126 | case LSL_DECREMENT_POST : fprintf(file, " _LSL.postDecrement"); break; |
2127 | case LSL_INCREMENT_POST : fprintf(file, " _postIncrement"); break; | 2127 | case LSL_INCREMENT_POST : fprintf(file, " _LSL.postIncrement"); break; |
2128 | default : | 2128 | default : |
2129 | break; | 2129 | break; |
2130 | } | 2130 | } |
@@ -2423,17 +2423,11 @@ static boolean doneParsing(LuaSL_compiler *compiler) | |||
2423 | out = fopen(luaName, "w"); | 2423 | out = fopen(luaName, "w"); |
2424 | if (out) | 2424 | if (out) |
2425 | { | 2425 | { |
2426 | fprintf(out, "--// Pre declared helper stuff.\n"); | ||
2427 | fprintf(out, "local _bit = require(\"bit\")\n"); | ||
2428 | fprintf(out, "_currentState = {}\n"); | ||
2429 | fprintf(out, "function _preDecrement(name) _G[name] = _G[name] - 1; return _G[name]; end;\n"); | ||
2430 | fprintf(out, "function _preIncrement(name) _G[name] = _G[name] + 1; return _G[name]; end;\n"); | ||
2431 | fprintf(out, "function _postDecrement(name) local temp = _G[name]; _G[name] = _G[name] - 1; return temp; end;\n"); | ||
2432 | fprintf(out, "function _postIncrement(name) local temp = _G[name]; _G[name] = _G[name] + 1; return temp; end;\n"); | ||
2433 | 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"); | ||
2434 | fprintf(out, "--// Generated code goes here.\n\n"); | 2426 | fprintf(out, "--// Generated code goes here.\n\n"); |
2427 | fprintf(out, "local _bit = require(\"bit\")\n"); | ||
2428 | fprintf(out, "local _LSL = require(\"LSL\")\n\n"); | ||
2435 | outputLeaf(out, OM_LUA, compiler->ast); | 2429 | outputLeaf(out, OM_LUA, compiler->ast); |
2436 | 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. | 2430 | fprintf(out, "\n\n--_LSL.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. |
2437 | fprintf(out, "\n--// End of generated code.\n\n"); | 2431 | fprintf(out, "\n--// End of generated code.\n\n"); |
2438 | fclose(out); | 2432 | fclose(out); |
2439 | sprintf(buffer, "../../libraries/luajit-2.0/src/luajit \"%s\"", luaName); | 2433 | sprintf(buffer, "../../libraries/luajit-2.0/src/luajit \"%s\"", luaName); |