summaryrefslogtreecommitdiff
path: root/indra/newview/llluamanager.cpp
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2023-09-28 10:57:32 -0400
committerNat Goodspeed <nat@lindenlab.com>2023-09-28 10:57:32 -0400
commit968a39245ae53136dc9263e3e1f4255f2e0bd41a (patch)
treef9ea4fb5a94647e663b5a487ea63b461d3a75f37 /indra/newview/llluamanager.cpp
parent7fccd662df48e5ddef0ec7e14a43289024bd27e1 (diff)
DRTVWR-589: Add Lua-callable await_event() function.
This suspends the calling Lua coroutine (and C++ coroutine on which the Lua state is running) until an event is received on the named LLEventPump. Returns the event. Pass optional timeout in seconds as a second argument. With no timeout, waits indefinitely. Pass optional timeout discriminator return value as a third argument (default nil).
Diffstat (limited to 'indra/newview/llluamanager.cpp')
-rw-r--r--indra/newview/llluamanager.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp
index 931faadf4b..483075583c 100644
--- a/indra/newview/llluamanager.cpp
+++ b/indra/newview/llluamanager.cpp
@@ -32,6 +32,7 @@
#include "llappearancemgr.h"
#include "llcallbacklist.h"
#include "llerror.h"
+#include "lleventcoro.h"
#include "llevents.h"
#include "llfloaterreg.h"
#include "llfloaterimnearbychat.h"
@@ -274,6 +275,7 @@ lua_function(print_debug)
return 0;
}
+// also used for print(); see LuaState constructor
lua_function(print_info)
{
luaL_where(L, 1);
@@ -677,6 +679,29 @@ lua_function(listen_events)
return 2;
}
+lua_function(await_event)
+{
+ // await_event(pumpname [, timeout [, value to return if timeout (default nil)]])
+ auto pumpname{ lua_tostdstring(L, 1) };
+ LLSD result;
+ if (lua_gettop(L) > 1)
+ {
+ auto timeout{ lua_tonumber(L, 2) };
+ // with no 3rd argument, should be LLSD()
+ auto dftval{ lua_tollsd(L, 3) };
+ lua_pop(L, lua_gettop(L));
+ result = llcoro::suspendUntilEventOnWithTimeout(pumpname, timeout, dftval);
+ }
+ else
+ {
+ // no timeout
+ lua_pop(L, 1);
+ result = llcoro::suspendUntilEventOn(pumpname);
+ }
+ lua_pushllsd(L, result);
+ return 1;
+}
+
/**
* RAII class to manage the lifespan of a lua_State
*/