diff options
-rw-r--r-- | indra/llcommon/lua_function.cpp | 22 | ||||
-rw-r--r-- | indra/newview/scripts/lua/WaitQueue.lua | 2 | ||||
-rw-r--r-- | indra/newview/scripts/lua/fiber.lua | 4 | ||||
-rw-r--r-- | indra/newview/scripts/lua/leap.lua | 10 | ||||
-rw-r--r-- | indra/newview/scripts/lua/test_LLGesture.lua | 2 | ||||
-rw-r--r-- | indra/newview/scripts/lua/test_luafloater_demo.lua | 5 | ||||
-rw-r--r-- | indra/newview/scripts/lua/test_luafloater_gesture_list.lua | 3 | ||||
-rw-r--r-- | indra/newview/tests/llluamanager_test.cpp | 24 |
8 files changed, 44 insertions, 28 deletions
diff --git a/indra/llcommon/lua_function.cpp b/indra/llcommon/lua_function.cpp index 441e17dafd..9f0abd5674 100644 --- a/indra/llcommon/lua_function.cpp +++ b/indra/llcommon/lua_function.cpp @@ -439,6 +439,8 @@ void LuaState::initLuaState() LuaFunction::init(mState); // Try to make print() write to our log. lua_register(mState, "print", LuaFunction::get("print_info")); + // We don't want to have to prefix require(). + lua_register(mState, "require", LuaFunction::get("require")); } LuaState::~LuaState() @@ -646,11 +648,20 @@ LuaFunction::LuaFunction(const std::string_view& name, lua_CFunction function, void LuaFunction::init(lua_State* L) { const auto& [registry, lookup] = getRState(); + luaL_checkstack(L, 2, nullptr); + // create LL table -- + // it happens that we know exactly how many non-array members we want + lua_createtable(L, 0, int(narrow(lookup.size()))); + int idx = lua_gettop(L); for (const auto& [name, pair]: registry) { const auto& [funcptr, helptext] = pair; - lua_register(L, name.c_str(), funcptr); + // store funcptr in LL table with saved name + lua_pushcfunction(L, funcptr, name.c_str()); + lua_setfield(L, idx, name.c_str()); } + // store LL in new lua_State's globals + lua_setglobal(L, "LL"); } lua_CFunction LuaFunction::get(const std::string& key) @@ -671,6 +682,15 @@ std::pair<LuaFunction::Registry&, LuaFunction::Lookup&> LuaFunction::getState() } /***************************************************************************** +* check_stop() +*****************************************************************************/ +lua_function(check_stop, "ensure that a Lua script responds to viewer shutdown") +{ + LLCoros::checkStop(); + return 0; +} + +/***************************************************************************** * help() *****************************************************************************/ lua_function(help, diff --git a/indra/newview/scripts/lua/WaitQueue.lua b/indra/newview/scripts/lua/WaitQueue.lua index a34dbef4d7..1fbcc50847 100644 --- a/indra/newview/scripts/lua/WaitQueue.lua +++ b/indra/newview/scripts/lua/WaitQueue.lua @@ -5,7 +5,7 @@ local fiber = require('fiber') local Queue = require('Queue') --- local debug = print_debug +-- local debug = LL.print_debug local function debug(...) end local WaitQueue = Queue:new() diff --git a/indra/newview/scripts/lua/fiber.lua b/indra/newview/scripts/lua/fiber.lua index 7dc67f510c..aebf27357f 100644 --- a/indra/newview/scripts/lua/fiber.lua +++ b/indra/newview/scripts/lua/fiber.lua @@ -222,8 +222,6 @@ local function scheduler() -- processing to the main thread. If called from a coroutine, pass control -- back to the main thread. if coroutine.running() then - -- seize the opportunity to make sure the viewer isn't shutting down --- check_stop() -- this is a real coroutine, yield normally to main thread coroutine.yield() -- main certainly still exists @@ -240,7 +238,7 @@ local function scheduler() repeat for co in live_ready_iter do -- seize the opportunity to make sure the viewer isn't shutting down --- check_stop() + LL.check_stop() -- before we re-append co, is it the only remaining entry? others = next(ready) -- co is live, re-append it to the ready list diff --git a/indra/newview/scripts/lua/leap.lua b/indra/newview/scripts/lua/leap.lua index 77f3a3e116..a60819d493 100644 --- a/indra/newview/scripts/lua/leap.lua +++ b/indra/newview/scripts/lua/leap.lua @@ -51,7 +51,7 @@ local leap = {} -- _command: string name of command LLEventPump. post_to(_command, ...) -- engages LLLeapListener operations such as listening on a specified other -- LLEventPump, etc. -leap._reply, leap._command = get_event_pumps() +leap._reply, leap._command = LL.get_event_pumps() -- Dict of features added to the LEAP protocol since baseline implementation. -- Before engaging a new feature that might break an older viewer, we can -- check for the presence of that feature key. This table is solely about the @@ -112,7 +112,7 @@ function leap.send(pump, data, reqid) end end debug('leap.send(%s, %s) calling post_on()', pump, data) - post_on(pump, data) + LL.post_on(pump, data) end -- common setup code shared by request() and generate() @@ -215,7 +215,7 @@ local function unsolicited(pump, data) return end end - print_debug(string.format('unsolicited(%s, %s) discarding unclaimed event', pump, data)) + LL.print_debug(string.format('unsolicited(%s, %s) discarding unclaimed event', pump, data)) end -- Route incoming (pump, data) event to the appropriate waiting coroutine. @@ -244,7 +244,7 @@ fiber.set_idle(function () return 'done' end debug('leap.idle() calling get_event_next()') - local ok, pump, data = pcall(get_event_next) + local ok, pump, data = pcall(LL.get_event_next) debug('leap.idle() got %s: %s, %s', ok, pump, data) -- ok false means get_event_next() raised a Lua error, pump is message if not ok then @@ -414,7 +414,7 @@ end -- called by leap.process() when get_event_next() raises an error function leap.WaitFor:exception(message) - print_warning(self.name .. ' error: ' .. message) + LL.print_warning(self.name .. ' error: ' .. message) self._queue:Error(message) end diff --git a/indra/newview/scripts/lua/test_LLGesture.lua b/indra/newview/scripts/lua/test_LLGesture.lua index 5c0db6c063..5897a0e3cb 100644 --- a/indra/newview/scripts/lua/test_LLGesture.lua +++ b/indra/newview/scripts/lua/test_LLGesture.lua @@ -22,7 +22,7 @@ coro.launch(function() print(name) LLGesture.startGesture(uuid) repeat - sleep(1) + LL.sleep(1) until not LLGesture.isGesturePlaying(uuid) end print('Done.') diff --git a/indra/newview/scripts/lua/test_luafloater_demo.lua b/indra/newview/scripts/lua/test_luafloater_demo.lua index be189bc146..c375a2abc7 100644 --- a/indra/newview/scripts/lua/test_luafloater_demo.lua +++ b/indra/newview/scripts/lua/test_luafloater_demo.lua @@ -1,7 +1,6 @@ XML_FILE_PATH = "luafloater_demo.xml" leap = require 'leap' -coro = require 'coro' fiber = require 'fiber' --event pump for sending actions to the floater @@ -11,7 +10,7 @@ event_list=leap.request("LLFloaterReg", {op="getFloaterEvents"}).events local function _event(event_name) if not table.find(event_list, event_name) then - print_warning("Incorrect event name: " .. event_name) + LL.print_warning("Incorrect event name: " .. event_name) end return event_name end @@ -41,7 +40,7 @@ function handleEvents(event_data) post({action="set_value", ctrl_name="time_lbl", value= getCurrentTime()}) end elseif event_data.event == _event("floater_close") then - print_warning("Floater was closed") + LL.print_warning("Floater was closed") leap.done() end end diff --git a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua index 7e2139468f..6d4a8e0cad 100644 --- a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua +++ b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua @@ -1,7 +1,6 @@ XML_FILE_PATH = "luafloater_gesture_list.xml" leap = require 'leap' -coro = require 'coro' fiber = require 'fiber' LLGesture = require 'LLGesture' @@ -12,7 +11,7 @@ event_list=leap.request("LLFloaterReg", {op="getFloaterEvents"}).events local function _event(event_name) if not table.find(event_list, event_name) then - print_warning("Incorrect event name: " .. event_name) + LL.print_warning("Incorrect event name: " .. event_name) end return event_name end diff --git a/indra/newview/tests/llluamanager_test.cpp b/indra/newview/tests/llluamanager_test.cpp index 872d7827fe..e10dedcf53 100644 --- a/indra/newview/tests/llluamanager_test.cpp +++ b/indra/newview/tests/llluamanager_test.cpp @@ -109,7 +109,7 @@ namespace tut listener([&fromlua](const LLSD& data){ fromlua = data; })); const std::string lua(stringize( "data = ", construct, "\n" - "post_on('testpump', data)\n" + "LL.post_on('testpump', data)\n" )); LuaState L; auto [count, result] = LLLUAmanager::waitScriptLine(L, lua); @@ -140,14 +140,14 @@ namespace tut { posts.push_back(data.asString()); })); const std::string lua( "-- test post_on,get_event_pumps,get_event_next\n" - "post_on('testpump', 'entry')\n" - "post_on('testpump', 'get_event_pumps()')\n" - "replypump, cmdpump = get_event_pumps()\n" - "post_on('testpump', replypump)\n" - "post_on('testpump', 'get_event_next()')\n" - "pump, data = get_event_next()\n" - "post_on('testpump', data)\n" - "post_on('testpump', 'exit')\n" + "LL.post_on('testpump', 'entry')\n" + "LL.post_on('testpump', 'get_event_pumps()')\n" + "replypump, cmdpump = LL.get_event_pumps()\n" + "LL.post_on('testpump', replypump)\n" + "LL.post_on('testpump', 'get_event_next()')\n" + "pump, data = LL.get_event_next()\n" + "LL.post_on('testpump', data)\n" + "LL.post_on('testpump', 'exit')\n" ); LuaState L; // It's important to let the startScriptLine() coroutine run @@ -179,9 +179,9 @@ namespace tut LLEventMailDrop testpump("testpump"); const std::string lua( "-- test LLSD round trip\n" - "replypump, cmdpump = get_event_pumps()\n" - "post_on('testpump', replypump)\n" - "pump, data = get_event_next()\n" + "replypump, cmdpump = LL.get_event_pumps()\n" + "LL.post_on('testpump', replypump)\n" + "pump, data = LL.get_event_next()\n" "return data\n" ); LuaState L; |