From 5fc1d9cce112bd0df3604be3a9efbc43ff5170a8 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 5 Feb 2012 18:19:39 +1000 Subject: Do script quitting differently, using the wire protocol method, which means I got to debug that. --- LuaSL/src/LSL.lua | 19 +++++++++++++------ LuaSL/src/LuaSL_compile.c | 2 +- LuaSL/src/LuaSL_main.c | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) (limited to 'LuaSL/src') diff --git a/LuaSL/src/LSL.lua b/LuaSL/src/LSL.lua index 59f706d..6473cc2 100644 --- a/LuaSL/src/LSL.lua +++ b/LuaSL/src/LSL.lua @@ -307,6 +307,13 @@ function LSL.postIncrement(name) local temp = _G[name]; _G[name] = _G[name] + 1; -- State stuff local currentState = {} +local running = true; + +-- Damn, looks like these sorts of functions have to be part of the table. +-- Coz pcall() runs in the context of the script, not this module, so needs to call _LSL.quit(). +function LSL.quit() + running = false +end function LSL.stateChange(x) if currentState ~= x then -- Changing to the same state is a NOP. @@ -347,18 +354,18 @@ function LSL.mainLoop(SID, x) LSL.stateChange(x); - -- 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. + -- TODO - Need a FIFO queue of incoming events. Which will be in the C main thread, coz that's listening on the socket for us. + -- Actually, I think the luaproc message system manages such a queue for us anyway. + -- C should strip off the "SID." part and replace it with "_LSL.", so might be better to restrict the wire protocol to single function calls. - while true do + while running do local message = luaproc.receive(sid) - if "quit()" == message then - return - elseif message then + if message then result, errorMsg = loadstring(message) if nil == result then print("Not a valid event: " .. message .. " ERROR MESSAGE: " .. errorMsg) else - status, result = pcall(result()) + status, result = pcall(result) if not status then print("Error from event: " .. message .. " ERROR MESSAGE: " .. result) elseif result then diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 72d94b9..f840b69 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -2275,7 +2275,7 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants) fprintf(out, "--// Generated code goes here.\n\n"); fprintf(out, "local _bit = require(\"bit\")\n"); - fprintf(out, "local _LSL = require(\"LSL\")\n\n"); + fprintf(out, "_LSL = require(\"LSL\")\n\n"); // Local might be quicker, but looks like we need global for pcall(), it has it's own local stack I think. // TODO - Use the scripts UUID instead of the file name here. fprintf(out, "local _SID = [=[%s.lua.out]=]\n\n", compiler.fileName); outputLeaf(out, OM_LUA, compiler.ast); diff --git a/LuaSL/src/LuaSL_main.c b/LuaSL/src/LuaSL_main.c index 5f48c5e..c441bc5 100644 --- a/LuaSL/src/LuaSL_main.c +++ b/LuaSL/src/LuaSL_main.c @@ -123,7 +123,7 @@ static void dirList_quit(const char *name, const char *path, void *data) snprintf(buf, sizeof(buf), "%s/%s.events", path, name); // PD("Quitting Lua script %s", buf); - status = sendToChannel(buf, "quit()"); + status = sendToChannel(buf, "_LSL.quit()"); if (status) PE("Error trying to kill script %s : %s", buf, status); } -- cgit v1.1