diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2024-04-02 11:29:29 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2024-04-02 11:29:29 -0400 |
commit | 1866d1a450b7857da82ceafbd2c6581d87b7f334 (patch) | |
tree | 983b8efa465dae24b82310d2aa3e2851573008fe /indra/newview/scripts/lua/test_luafloater_gesture_list.lua | |
parent | cc8299d153b9aa81558951cb6b1a19693fb52982 (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_gesture_list.lua')
-rw-r--r-- | indra/newview/scripts/lua/test_luafloater_gesture_list.lua | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua index 6d4a8e0cad..a907eb2e90 100644 --- a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua +++ b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua @@ -1,11 +1,17 @@ -XML_FILE_PATH = "luafloater_gesture_list.xml" +XML_FILE_PATH = LL.source_dir() .. "/luafloater_gesture_list.xml" + +scriptparts = string.split(LL.source_path(), '/') +scriptname = scriptparts[#scriptparts] +print('Running ' .. scriptname) leap = require 'leap' fiber = require 'fiber' LLGesture = require 'LLGesture' +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 @@ -22,9 +28,12 @@ end function handleEvents(event_data) if event_data.event == _event("floater_close") then - leap.done() - elseif event_data.event == _event("post_build") then + return false + end + + if event_data.event == _event("post_build") then COMMAND_PUMP_NAME = event_data.command_name + reqid = event_data.reqid gestures_uuid = LLGesture.getActiveGestures() local action_data = {} action_data.action = "add_list_element" @@ -40,8 +49,10 @@ function handleEvents(event_data) LLGesture.startGesture(event_data.value) end end + return true end +startup.wait('STATE_STARTED') local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} --receive additional events for defined control {<control_name>= {action1, action2, ...}} key.extra_events={gesture_list = {_event("double_click")}} @@ -49,13 +60,14 @@ handleEvents(leap.request("LLFloaterReg", key)) 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 |