summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-03-25 16:29:17 -0400
committerNat Goodspeed <nat@lindenlab.com>2024-03-25 16:29:17 -0400
commitac4fa418e3a7402f9d9122c726d2fbfc4b8767b2 (patch)
treeea670314a74d9ad82e616fd035283c86740d63fc
parent2eb6901c7c9ae87a588d99399e4b41640e4c4881 (diff)
Add LL. prefix to viewer entry points, fix existing references.
-rw-r--r--indra/llcommon/lua_function.cpp13
-rw-r--r--indra/newview/scripts/lua/WaitQueue.lua2
-rw-r--r--indra/newview/scripts/lua/leap.lua10
-rw-r--r--indra/newview/scripts/lua/test_LLGesture.lua2
-rw-r--r--indra/newview/scripts/lua/test_luafloater_demo.lua6
-rw-r--r--indra/newview/scripts/lua/test_luafloater_gesture_list.lua2
-rw-r--r--indra/newview/tests/llluamanager_test.cpp24
7 files changed, 35 insertions, 24 deletions
diff --git a/indra/llcommon/lua_function.cpp b/indra/llcommon/lua_function.cpp
index 441e17dafd..962e9ee2fa 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)
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/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 b81259c060..4e071e4abe 100644
--- a/indra/newview/scripts/lua/test_luafloater_demo.lua
+++ b/indra/newview/scripts/lua/test_luafloater_demo.lua
@@ -16,7 +16,7 @@ leap.process()
local function _event(event_name)
if not util.contains(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
@@ -45,7 +45,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
@@ -75,4 +75,4 @@ end
coro.launch(process_events, catch_events)
leap.process()
-print_warning("End of the script")
+LL.print_warning("End of the script")
diff --git a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua
index b46e36b4d9..9c718c353b 100644
--- a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua
+++ b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua
@@ -17,7 +17,7 @@ leap.process()
local function _event(event_name)
if not util.contains(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;