aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-02-05 16:38:50 +1000
committerDavid Walter Seikel2012-02-05 16:38:50 +1000
commit53fe89764f8f679f3f4cbaa39c2393918898815f (patch)
tree6e6889754e1292d48ce407e2ba93b9bea4f827f6 /LuaSL
parentA commented out debuggie that I might need later. (diff)
downloadSledjHamr-53fe89764f8f679f3f4cbaa39c2393918898815f.zip
SledjHamr-53fe89764f8f679f3f4cbaa39c2393918898815f.tar.gz
SledjHamr-53fe89764f8f679f3f4cbaa39c2393918898815f.tar.bz2
SledjHamr-53fe89764f8f679f3f4cbaa39c2393918898815f.tar.xz
Implement the script main loop, and the script UUID, which we call SID, though for now it's only the file name.
Diffstat (limited to 'LuaSL')
-rw-r--r--LuaSL/src/LSL.lua42
-rw-r--r--LuaSL/src/LuaSL_compile.c4
2 files changed, 36 insertions, 10 deletions
diff --git a/LuaSL/src/LSL.lua b/LuaSL/src/LSL.lua
index 0b02077..975f219 100644
--- a/LuaSL/src/LSL.lua
+++ b/LuaSL/src/LSL.lua
@@ -335,16 +335,40 @@ function LSL.stateChange(x)
335 end 335 end
336end; 336end;
337 337
338function LSL.mainLoop(x) 338function LSL.mainLoop(SID, x)
339 -- TODO - disabled the stuff that waits until I implement the stuff that makes it stop waiting. lol
340 local sid = SID .. ".events"
341 local status, errorMsg = "disabled" -- = luaproc.newchannel(sid)
342 local result
343
344 if not status then
345 print("Can't open the luaproc channel " .. sid .. " ERROR MESSAGE: " .. errorMsg)
346 return
347 end
348
339 LSL.stateChange(x); 349 LSL.stateChange(x);
340 --[[ TODO - 350
341 Sits around waiting for events. This should be "wait for a message" in luaproc. 351 -- TODO - Need a FIFO stack of incoming events. Which will be in the C main thread, coz that's listening on the socket for us.
342 Incoming events can be the same format as the OpenSim SID.event.* protocol on the wiki. 352
343 When we get an event, run it, then go back to waiting. 353-- while true do
344 354 local message = luaproc.receive(sid)
345 Need a FIFO stack of incoming events. 355 if message then
346 Which will be in the C main thread, coz that's listening on the socket for us. 356 result, errorMsg = loadstring(message)
347 ]] 357 if nil == result then
358 print("Not a valid event: " .. message .. " ERROR MESSAGE: " .. errorMsg)
359 else
360 status, result = pcall(result())
361 if not status then
362 print("Error from event: " .. message .. " ERROR MESSAGE: " .. result)
363 elseif result then
364 status, errorMsg = luaproc.send(sid, result)
365 if not status then
366 print("Error sending results from event: " .. message .. " ERROR MESSAGE: " .. errorMsg)
367 end
368 end
369 end
370 end
371-- end
348end 372end
349 373
350-- Typecasting stuff. 374-- Typecasting stuff.
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c
index 80eda62..4821589 100644
--- a/LuaSL/src/LuaSL_compile.c
+++ b/LuaSL/src/LuaSL_compile.c
@@ -2276,8 +2276,10 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants)
2276 fprintf(out, "--// Generated code goes here.\n\n"); 2276 fprintf(out, "--// Generated code goes here.\n\n");
2277 fprintf(out, "local _bit = require(\"bit\")\n"); 2277 fprintf(out, "local _bit = require(\"bit\")\n");
2278 fprintf(out, "local _LSL = require(\"LSL\")\n\n"); 2278 fprintf(out, "local _LSL = require(\"LSL\")\n\n");
2279 // TODO - Use the scripts UUID instead of the file name here.
2280 fprintf(out, "local _SID = [=[%s]=]\n\n", compiler.fileName);
2279 outputLeaf(out, OM_LUA, compiler.ast); 2281 outputLeaf(out, OM_LUA, compiler.ast);
2280 fprintf(out, "\n\n_LSL.mainLoop(_defaultState)\n"); // This actually starts the script running. 2282 fprintf(out, "\n\n_LSL.mainLoop(_SID, _defaultState)\n"); // This actually starts the script running.
2281 fprintf(out, "\n--// End of generated code.\n\n"); 2283 fprintf(out, "\n--// End of generated code.\n\n");
2282 fclose(out); 2284 fclose(out);
2283 2285