From c9d2172efbc91b2709dd782a06c936d79e8e0802 Mon Sep 17 00:00:00 2001 From: pixel Date: Sat, 5 Jul 2008 06:24:43 +0000 Subject: Using a real Lua thread for the threaded command line. --- src/lua-interface.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/lua-interface.cpp b/src/lua-interface.cpp index d4e56c2..dc97f12 100644 --- a/src/lua-interface.cpp +++ b/src/lua-interface.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: lua-interface.cpp,v 1.3 2008-07-04 14:31:23 pixel Exp $ */ +/* $Id: lua-interface.cpp,v 1.4 2008-07-05 06:24:43 pixel Exp $ */ #define WIP @@ -199,8 +199,6 @@ class LuaStderrPrinter : public LuaPrinter { LuaStderrPrinter lp_stderr; -Lua * L = 0; - String server_fname = "server.lua"; static int StartTaskLoop(void * foo) { @@ -390,14 +388,15 @@ String * LUACall_Descs[] = {0}; class ReloadLUA : public Message { public: - ReloadLUA(const String & title = "Reloading " + server_fname, const String & url = "reloadlua"); + ReloadLUA(Lua * L, const String & title = "Reloading " + server_fname, const String & url = "reloadlua"); virtual ~ReloadLUA() { } virtual Task * Do(Variables *, Variables *, Handle *); private: + Lua * L; }; -ReloadLUA::ReloadLUA(const String & _title, const String & _url) : Message(_title, "Reloading " + server_fname + " in progress.", _url, 0) { +ReloadLUA::ReloadLUA(Lua * __L, const String & _title, const String & _url) : L(__L), Message(_title, "Reloading " + server_fname + " in progress.", _url, 0) { } Task * ReloadLUA::Do(Variables * v, Variables * headers, Handle * h) { @@ -407,12 +406,14 @@ Task * ReloadLUA::Do(Variables * v, Variables * headers, Handle * h) { class LUACall : public Message { public: - LUACall(const String & title = "Calling a function.", const String & url = "luacall"); + LUACall(Lua * L, const String & title = "Calling a function.", const String & url = "luacall"); virtual ~LUACall() { } virtual Task * Do(Variables *, Variables *, Handle *); + private: + Lua * L; }; -LUACall::LUACall(const String & _title, const String & _url) : Message(_title, "Function call in progress...", _url, 0) { +LUACall::LUACall(Lua * __L, const String & _title, const String & _url) : L(__L), Message(_title, "Function call in progress...", _url, 0) { } Task * LUACall::Do(Variables * v, Variables * headers, Handle * h) { @@ -430,7 +431,7 @@ CODE_BEGINS /* That's the basic lua starter for non interactive mode */ Lua * start_basic_lua(void) { - L = new threaded_Lua(); + Lua * L = new threaded_Lua(); L->lock(); @@ -523,14 +524,13 @@ class lua_interface_printer_t : public printer_t { Handle * log; }; -static void * interactive_prompt(void * foo) { +static void * interactive_prompt(void * __L) { char prompt[10], * line_read = 0; String line, endline; bool runit; Buffer command; int pos; - - + Lua * L = (Lua *) __L; /* Interactive mode loop */ strcpy(prompt, "> "); @@ -748,13 +748,14 @@ virtual int startup() throw (GeneralException) { } if (interactive) { - pthread_create(&interactive_thread, NULL, interactive_prompt, NULL); + pthread_create(&interactive_thread, NULL, interactive_prompt, L->thread(true)); + L->pop(); } if (server) { HttpServ * httpserv = new HttpServ(new Message("Welcome", "Welcome.", "start"), hport.to_int(), "Lua Interface"); - new Form("LUACall", "luacallform", "Enter the function name to call", LUACall_Names, LUACall_Invites, LUACall_Defaults, LUACall_Lists, LUACall_Descs, 1, new LUACall()); - new ReloadLUA(); + new Form("LUACall", "luacallform", "Enter the function name to call", LUACall_Names, LUACall_Invites, LUACall_Defaults, LUACall_Lists, LUACall_Descs, 1, new LUACall(L)); + new ReloadLUA(L); new LuaCommandLine(L, tport.to_int()); L->load(&Input(server_fname)); -- cgit v1.2.3