summaryrefslogtreecommitdiff
path: root/indra/newview/tests
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2024-02-22 20:42:08 -0500
committerNat Goodspeed <nat@lindenlab.com>2024-02-22 20:42:08 -0500
commit85ef003ed7836cb351ee62ed44a4837a305e9dbd (patch)
tree6d747a2961291e46c5eadd23f8b9e30ce8101d7f /indra/newview/tests
parent484b91dd65c8029ad5a52a6b4684d9046df709ac (diff)
Lua listen_events(), await_event() => get_event_{pumps,next}().
Don't set up a Lua callback to receive incoming events, a la listen_events(). Don't listen on an arbitrary event pump, a la await_event(). Instead, the new get_event_pumps() entry point simply delivers the reply pump and command pump names (as listen_events() did) without storing a Lua callback. Make LuaListener capture incoming events on the reply pump in a queue. This avoids the problem of multiple events arriving too quickly for the Lua script to retrieve. If the queue gets too big, discard the excess instead of blocking the caller of post(). Then the new get_event_next() entry point retrieves the next (pump, data) pair from the queue, blocking the Lua script until a suitable event arrives. This is closer to the use of stdin for a LEAP plugin. It also addresses the question: what should the Lua script's C++ coroutine do while waiting for an incoming reply pump event? Recast llluamanager_test.cpp for this new, more straightforward API. Move LLLeap's and LuaListener's reply LLEventPump into LLLeapListener, which they both use. This simplifies LLLeapListener's API, which was a little convoluted: the caller supplied a connect callback to allow LLLeapListener to connect some listener to the caller's reply pump. Now, instead, the caller simply passes a bool(pumpname, data) callback to receive events incoming on LLLeapListener's own reply pump. Fix a latent bug in LLLeapListener: if a plugin called listen() more than once with the same listener name, the new connection would not have been saved. While at it, replace some older Boost features in LLLeapListener and LLLeap.
Diffstat (limited to 'indra/newview/tests')
-rw-r--r--indra/newview/tests/llluamanager_test.cpp35
1 files changed, 14 insertions, 21 deletions
diff --git a/indra/newview/tests/llluamanager_test.cpp b/indra/newview/tests/llluamanager_test.cpp
index 1f25fd5f3b..81ec186cf4 100644
--- a/indra/newview/tests/llluamanager_test.cpp
+++ b/indra/newview/tests/llluamanager_test.cpp
@@ -108,7 +108,6 @@ namespace tut
replypump.listen("llluamanager_test",
listener([&fromlua](const LLSD& data){ fromlua = data; })));
const std::string lua(stringize(
- "-- test LLSD synthesized by Lua\n",
"data = ", construct, "\n"
"post_on('testpump', data)\n"
));
@@ -134,7 +133,7 @@ namespace tut
template<> template<>
void object::test<3>()
{
- set_test_name("test post_on(), listen_events(), await_event()");
+ set_test_name("test post_on(), get_event_pumps(), get_event_next()");
StringVec posts;
LLEventStream replypump("testpump");
LLTempBoundListener conn(
@@ -142,17 +141,14 @@ namespace tut
listener([&posts](const LLSD& data)
{ posts.push_back(data.asString()); })));
const std::string lua(
- "-- test post_on,listen_events,await_event\n"
+ "-- test post_on,get_event_pumps,get_event_next\n"
"post_on('testpump', 'entry')\n"
- "callback = function(pump, data)\n"
- " -- just echo the data we received\n"
- " post_on('testpump', data)\n"
- "end\n"
- "post_on('testpump', 'listen_events()')\n"
- "replypump, cmdpump = listen_events(callback)\n"
+ "post_on('testpump', 'get_event_pumps()')\n"
+ "replypump, cmdpump = get_event_pumps()\n"
"post_on('testpump', replypump)\n"
- "post_on('testpump', 'await_event()')\n"
- "await_event(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"
);
LuaState L;
@@ -162,9 +158,9 @@ namespace tut
auto future = LLLUAmanager::startScriptLine(L, lua);
StringVec expected{
"entry",
- "listen_events()",
+ "get_event_pumps()",
"",
- "await_event()",
+ "get_event_next()",
"message",
"exit"
};
@@ -188,18 +184,15 @@ namespace tut
listener([&reply](const LLSD& post){ reply = post; })));
const std::string lua(
"-- test LLSD round trip\n"
- "callback = function(pump, data)\n"
- " -- just echo the data we received\n"
- " post_on('testpump', data)\n"
- "end\n"
- "replypump, cmdpump = listen_events(callback)\n"
+ "replypump, cmdpump = get_event_pumps()\n"
"post_on('testpump', replypump)\n"
- "await_event(replypump)\n"
+ "pump, data = get_event_next()\n"
+ "return data\n"
);
LuaState L;
auto future = LLLUAmanager::startScriptLine(L, lua);
// We woke up again ourselves because the coroutine running Lua has
- // reached the await_event() call, which suspends the calling C++
+ // reached the get_event_next() call, which suspends the calling C++
// coroutine (including the Lua code running on it) until we post
// something to that reply pump.
auto luapump{ reply.asString() };
@@ -208,7 +201,7 @@ namespace tut
// The C++ coroutine running the Lua script is now ready to run. Run
// it so it will echo the LLSD back to us.
auto [count, result] = future.get();
- ensure_equals(desc, reply, expect);
+ ensure_equals(desc, result, expect);
}
// Define an RTItem to be used for round-trip LLSD testing: what it is,