summaryrefslogtreecommitdiff
path: root/indra/newview/scripts/lua/test_luafloater_demo.lua
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-04-02 11:29:29 -0400
committerNat Goodspeed <nat@lindenlab.com>2024-04-02 11:29:29 -0400
commit1866d1a450b7857da82ceafbd2c6581d87b7f334 (patch)
tree983b8efa465dae24b82310d2aa3e2851573008fe /indra/newview/scripts/lua/test_luafloater_demo.lua
parentcc8299d153b9aa81558951cb6b1a19693fb52982 (diff)
Add startup.lua module with startup.ensure(), wait() functions.
This lets a calling script verify that it's running at the right point in the viewer's life cycle. A script that wants to interact with the SL agent wouldn't work if run from the viewer's command line -- unless it calls startup.wait("STATE_STARTED"), which pauses until login is complete. Modify test_luafloater_demo.lua and test_luafloater_gesture_list.lua to find their respective floater XUI files in the same directory as themselves. Make them both capture the reqid returned by the "showLuaFloater" operation, and filter for events bearing the same reqid. This paves the way for a given script to display more than one floater concurrently. Make test_luafloater_demo.lua (which does not require in-world resources) wait until 'STATE_LOGIN_WAIT', the point at which the viewer has presented the login screen. Make test_luafloater_gesture_list.lua (which interacts with the agent) wait until 'STATE_STARTED', the point at which the viewer is fully in world. Either or both can now be launched from the viewer's command line.
Diffstat (limited to 'indra/newview/scripts/lua/test_luafloater_demo.lua')
-rw-r--r--indra/newview/scripts/lua/test_luafloater_demo.lua25
1 files changed, 18 insertions, 7 deletions
diff --git a/indra/newview/scripts/lua/test_luafloater_demo.lua b/indra/newview/scripts/lua/test_luafloater_demo.lua
index c375a2abc7..c2d16d4f88 100644
--- a/indra/newview/scripts/lua/test_luafloater_demo.lua
+++ b/indra/newview/scripts/lua/test_luafloater_demo.lua
@@ -1,10 +1,16 @@
-XML_FILE_PATH = "luafloater_demo.xml"
+XML_FILE_PATH = LL.source_dir() .. "/luafloater_demo.xml"
+
+scriptparts = string.split(LL.source_path(), '/')
+scriptname = scriptparts[#scriptparts]
+print('Running ' .. scriptname)
leap = require 'leap'
fiber = require 'fiber'
+startup = require 'startup'
--event pump for sending actions to the floater
-COMMAND_PUMP_NAME = ""
+local COMMAND_PUMP_NAME = ""
+local reqid
--table of floater UI events
event_list=leap.request("LLFloaterReg", {op="getFloaterEvents"}).events
@@ -41,24 +47,29 @@ function handleEvents(event_data)
end
elseif event_data.event == _event("floater_close") then
LL.print_warning("Floater was closed")
- leap.done()
+ return false
end
+ return true
end
+startup.wait('STATE_LOGIN_WAIT')
local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"}
--sign for additional events for defined control {<control_name>= {action1, action2, ...}}
key.extra_events={show_time_lbl = {_event("right_mouse_down"), _event("double_click")}}
-COMMAND_PUMP_NAME = leap.request("LLFloaterReg", key).command_name
+local resp = leap.request("LLFloaterReg", key)
+COMMAND_PUMP_NAME = resp.command_name
+reqid = resp.reqid
catch_events = leap.WaitFor:new(-1, "all_events")
function catch_events:filter(pump, data)
- return data
+ if data.reqid == reqid then
+ return data
+ end
end
function process_events(waitfor)
event_data = waitfor:wait()
- while event_data do
- handleEvents(event_data)
+ while event_data and handleEvents(event_data) do
event_data = waitfor:wait()
end
end