From 968a39245ae53136dc9263e3e1f4255f2e0bd41a Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 28 Sep 2023 10:57:32 -0400 Subject: 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). --- indra/newview/llluamanager.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'indra/newview/llluamanager.cpp') 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 */ -- cgit v1.2.3