summaryrefslogtreecommitdiff
path: root/indra/newview/llluamanager.cpp
AgeCommit message (Collapse)Author
2024-02-07Add LLLUAmanager::startScriptFile(), startScriptLine() functions.Nat Goodspeed
Break out for LLLUAmanager consumers the promise/future semantics of waitScriptFile() and waitScriptLine(). startScriptMumble() uses runScriptMumble() to launch a coroutine to run the specified Lua script or chunk, providing an internal adapter callback to set a promise on completion. It then returns to its caller the future obtained from that promise. This allows a caller to call startScriptMumble(), run in parallel with the Lua coroutine for a while and then call get() on the returned future to wait for results. waitScriptMumble() is then trivially implemented using startScriptMumble(). Fix runScriptLine()'s logic to abbreviate the passed Lua chunk for use as the description. We were erroneously assigning back through a string_view of the parameter, which overwrote a temporary string in the argument list. With Lua 5.4, listen_events() tried to discover the main "thread" (Lua coroutine) associated with the current lua_State so we could call async callbacks on that thread. Luau doesn't seem to provide that feature, so run callbacks on whichever thread calls listen_events(). Reinstate original multi-argument lua_print_msg(), tweaked to avoid the Lua 5.4 lua_rotate() function, which is missing from Luau.
2024-02-07Add machinery to capture result of running a Lua script or snippet.Nat Goodspeed
Add LuaState::expr() that evaluates a Lua snippet and reports back any result (or error) left on the stack. Add LLLUAmanager::runScriptFile() and runScriptLine() overloads that accept a callback with an (int count, LLSD result) signature. The count disambiguates (error, no result, one result, array of results). Also add overloads that accept an existing LuaState instance. Also add waitScriptFile() and waitScriptLine() methods that pause the calling coroutine until the Lua script completes, and return its results. Instead of giving LuaState a description to use for all subsequent checkLua() calls, remove description from its constructor and data members. Move to expr() and checkLua() parameters: we want a description specific to each operation, rather than for the LuaState as a whole. This prepares for persistent LuaState instances. For now, the existing script_finished_fn semantics remain: the callback will be called only when the LuaState is destroyed. This may need to change as we migrate towards longer-lasting LuaState instances. Make lua_function(name) macro append suffixes to the name for both the LuaFunction subclass declaration and the instance declaration. This allows publishing a lua_function() name such as sleep(), which already has a different C++ declaration. Move the Lua sleep() entry point to a standalone lua_function(sleep), instead of a lambda in the body of runScriptFile().
2024-02-06Break out lua_function.h,.cpp and lualistener.h,.cpp.Nat Goodspeed
The intention is to decentralize Luau entry points into our C++ code, permitting a given entry point to be added to the .cpp file that already deals with that class or functional area. Continuing to add every such entry point to llluamanager.cpp doesn't scale well. Extract LuaListener class from llluamanager.cpp to its own header and .cpp file. Extract from llluamanager into lua_function.h (and .cpp) declarations useful for adding a lua_function Luau entry point, e.g.: lua_register() lua_rawlen() lua_tostdstring() lua_pushstdstring() lua_tollsd() lua_pushllsd() LuaPopper lua_function() and LuaFunction class LuaState lua_what lua_stack DebugExit
2024-01-31strip lua testing functionsMnikolenko Productengine
2024-01-29DRTVWR-589: get rid of pragma and update windows libsMnikolenko Productengine
2024-01-26DRTVWR-589: update to start using Luau libsMnikolenko Productengine
2023-11-09DRTVWR-589 - don't prevent mangling names as we use C++ libMnikolenko Productengine
2023-11-02DRTVWR-589: Update Lualibs.cmake to use lua54.lib from 3p-lua.Nat Goodspeed
Also remove #pragma comment(lib, "liblua54.a") from relevant source files.
2023-10-19DRTVWR-589: Fix unreferenced LuaListener::mState member.Nat Goodspeed
2023-10-07DRTVWR-589: Solved the bug in traversing nested Lua tables.Nat Goodspeed
When lua_tollsd() makes a recursive call, it passes -1 as the index of the newly-encountered nested table. To traverse the nested table, lua_tollsd() starts by pushing nil as the initial key. But then calling lua_next(-1) finds nil -- NOT the nested table! Converting the index parameter to absolute before pushing nil solves.
2023-10-04DRTVWR-589: Add tests for LLSD-to-Lua round-trip conversions.Nat Goodspeed
Add from_lua() function to run a small Lua script that constructs a specified Lua object and posts it back to the test program via a temporary LLEventPump. Call this with a variety of Lua objects, comparing to the expected LLSD. Add round_trip() function to run another small Lua script that listens for incoming LLEventPump events and, for each, posts the received Lua data back to the test program as LLSD. Call this with a variety of LLSD objects, comparing to the expected LLSD. Also collect these objects into an LLSD array and send that for a round trip; also collect into an LLSD map and send that. Sadly, tests currently drive an access violation when trying to convert a nested Lua table to LLSD. Add verbose debug logging to lua_tollsd() to identify the context at which we hit the access violation. Add comments describing further exceptions to LLSD-to-Lua round trip identity. Add lua_what() iostream manipulator to stream whatever we can readily discover about a value at a specified Lua stack index. Add lua_stack() to report the contents of the Lua stack. Since the stack is created anew for every call to a C function, this shouldn't usually be enormous. Add hexdump.h with iostream manipulators to dump a byte range as hex digits, or to produce readable text from a mix of printing and nonprinting ASCII characters.
2023-10-03Merge branch 'DRTVWR-589' of github.com:/secondlife/viewer-private into ↵Brad Payne (Vir Linden)
DRTVWR-589
2023-10-03DRTVWR-589 - more demo workBrad Payne (Vir Linden)
2023-10-02DRTVWR-589: Add initial integration test for LLLUAmanager.Nat Goodspeed
The first test runs a Lua script that calls post_on(), listen_events() and await_event() to engage in LLEventPump handshakes with the test program. Make llluamanager.cpp testable by putting LL_TEST conditionals around lots of viewer-internals headers and the lua_function definitions that engage them. Since LuaListener::connect() is called by its constructor, make it a static method that explicitly accepts the lua_State* (instead of finding it as mState). Add that parameter to its two existing calls. Add a debug log message when LuaListener is destroyed. This surfaced the need to pass a no-op deleter when listen_events() constructs a LuaListener::ptr_t. When compiled for LL_TEST, make LuaListener::mReplyPump an LLEventLogProxyFor<LLEventStream> instead of a plain LLEventStream. For debugging purposes, add a type string "LLEventLogProxy" for LLEventPumps::make(). A make() call with this type will return an LLEventLogProxyFor<LLEventStream>.
2023-09-30DRTVWR-589: Emulate print() better, show output on Lua floater.Nat Goodspeed
Break out a lua_print_msg() function common to print_debug(), print_info() and print_warning(). Instead of accepting a single argument, lua_print_msg() accepts arbitrary arguments, passing each to the Lua tostring() function and concatenating the results. In addition to returning the combined string to its caller for level-appropriate logging, it also posts the message to a "lua output" LLEventPump for any interested party. Make LLFloaterLUADebug listen on "lua output" when the floater is constructed, storing the connection in an LLTempBoundListener to stop listening when the floater is destroyed. Append each message to the floater's output panel with a line break. Make LLTextEditor::addLineBreakChar() public. insertText("\n") only appends a little rectangle glyph. Enlarge the text capacity of the floater's output panel to be able to report whatever messages a Lua script wants to print. Add diagnostic logging for posting events from Lua, and receiving events to forward to Lua. Since lua_pop() is a macro implemented on lua_settop(), replace the awkward construct lua_pop(L, lua_gettop(L)) with lua_settop(L, 0). Use lambdas instead of std::bind() to connect LuaListener and LLLeapListener.
2023-09-28DRTVWR-589 - support for moving to destMnikolenko Productengine
2023-09-28DRTVWR-589: Call lua_pushstdstring() correctly.Nat Goodspeed
2023-09-28DRTVWR-589: Merge remote branch 'DRTVWR-589' into DRTVWR-589Nat Goodspeed
2023-09-28DRTVWR-589: Rename post_on_pump() to post_on()Nat Goodspeed
Sprinkle lua_checkstack() calls into functions that push to the Lua stack -- particularly important when traversing nested data structures of unknown depth! Tweak lua_pushllsd() handling of LLSD arrays.
2023-09-28DRTVWR-589: Add Lua-callable await_event() function.Nat Goodspeed
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).
2023-09-28DRTVWR-589: Try to override Lua's built-in print() with print_info()Nat Goodspeed
so Lua print() output will go to the viewer log, instead of getting discarded and possibly causing failures when the buffer fills and there's no open stdout file handle. Also name each Lua C++ coroutine with the description we give the LuaState instance.
2023-09-28DRTVWR-589 - support for rezing primsMnikolenko Productengine
2023-09-27DRTVWR-589: Always check regtype to avoid unref errorNat Goodspeed
2023-09-27DRTVWR-589: Use std::placeholders::_1, etc., for std::bind()Nat Goodspeed
2023-09-27DRTVWR-589: Fix compile errors in 354585d.Nat Goodspeed
2023-09-27DRTVWR-589: Add Lua-callable listen_events() function.Nat Goodspeed
Add LuaListener, based on LLLeap. LuaListener has an int key so the second and subsequent calls to listen_events() can find a previously-created one. LuaListener listens on its LLEventPump and arranges to call the specified Lua callback with any incoming event. It also instantiates an LLLeapListener. listen_events() locates the main thread for its state: we only want to call callbacks on the Lua chunk's main thread, not on a (possibly suspended) coroutine. It finds or creates a LuaListener and stashes it in the main thread's registry, along with the passed Lua callback function. Finally it returns the names of the LuaListener's reply pump and the LLLeapListener's command pump. Add LuaState RAII class to manage the lifespan of each lua_State we create. This encapsulates much of the boilerplate common to runScriptFile() and runScriptLine(). In addition, LuaState's destructor checks for a LuaListener key and, if found, destroys the referenced LuaListener. LuaState's constructor requires a description to clarify log messages. Move the checkLua() free function to a member of LuaState. This allows capturing an error message to pass to the C++ completion callback, if any. Use LuaState in runScriptFile() and runScriptLine(), synthesizing a suitable description in each case. Add print_debug() and print_info() logging calls, analogous to print_warning(). Add luaL_where() prefix to every such message. Add lua_pushstdstring(), like lua_tostdstring(): convenience for working with the pointer and length used by lua_pushlstring() and lua_tolstring(). Clean up return values of lua_functions. A lua_CFunction returns the number of return values it has pushed, so any 'void' lua_CFunction should pop its arguments and return 0.
2023-09-26DRTVWR-589: Fix typo due to old documentation.Nat Goodspeed
The function formerly known as luaL_typerror() is now luaL_typeerror().
2023-09-26DRTVWR-589: Collect int table keys in vector<int>, not set<int>.Nat Goodspeed
Given that we at least have a possibility of determining the length of a Lua table in advance, we might be able to populate a vector of keys with a single initial allocation. Even if Lua reports the length incorrectly, vector::push_back() is one of the bread-and-butter operations of the library, optimized to the extent possible. Inserting elements into a set seems more likely to incur allocations. Of course, we must then sort() the vector to determine its largest key value. Also document the requirement that we use a Lua runtime compiled for C++, that is, compiled to raise errors by C++ exceptions rather than by longjmp(). We rely on temporary stack objects being properly destroyed even if errors are raised. Conventionally, with lua_tomumble(L, index), 'index' refers to the stack index of the Lua object being converted to C++. For a Lua table, talk about table keys rather than table indexes to avoid confusing the maintainer.
2023-09-25DRTVWR-589: Fix Lua table to LLSD array conversion.Nat Goodspeed
The previous implementation assumed that the Lua length function would correctly report the number of entries in a table, and that traversing a table with integer keys would produce them in numeric order. Neither assumption is true. Instead, make a preliminary pass to validate and collect indexes, and to discover the highest integer index. Armed with that, we can construct a contiguous LLSD array of correct size, and populate it with a second pass. Also add Lua-callable post_on_pump(pumpname, datablob) function.
2023-09-22DRTVWR-589: Introduce LuaFunction: simplified function registration.Nat Goodspeed
2023-09-22DRTVWR-589: Existing lua_pushmumble() functions usually return void.Nat Goodspeed
2023-09-22DRTVWR-589: lua_objlen() removed, use lua_rawlen() insteadNat Goodspeed
2023-09-21DRTVWR-589: lua_objlen() only defined in luaconf.hNat Goodspeed
2023-09-21DRTVWR-589: Merge branch 'DRTVWR-589-llsd' into DRTVWR-589Nat Goodspeed
It seems TC only builds specific v-p branches, e.g. DRTVWR-589 but not DRTVWR-589-llsd.
2023-09-21DRTVWR-589: Add lua_tollsd() and lua_pushllsd() functions.Nat Goodspeed
2023-09-21DRTVWR-589 - allow adding branch to the menuMnikolenko Productengine
2023-09-21DRTVWR-589 - adding menu items to the top menuMnikolenko Productengine
2023-09-20DRTVWR-589 - added play animation and started to collect demo scriptsBrad Payne (Vir Linden)
2023-09-19Merge branch 'DRTVWR-589' of github.com:/secondlife/viewer-private into ↵Brad Payne (Vir Linden)
DRTVWR-589
2023-09-19DRTVWR-589 - click_child, limited support for pushing buttons in a floaterBrad Payne (Vir Linden)
2023-09-19lua support for notificationsMnikolenko Productengine
2023-09-18DRTVWR-589 - close_floater by nameBrad Payne (Vir Linden)
2023-09-14DRTVWR-589 - lua support parameter to UI commandsBrad Payne (Vir Linden)
2023-09-14Merge branch 'DRTVWR-589' of github.com:/secondlife/viewer-private into ↵Brad Payne (Vir Linden)
DRTVWR-589
2023-09-14DRTVWR-589 - LUA support for UI commands, only if no parametersBrad Payne (Vir Linden)
2023-09-13autorun selected script after loginMnikolenko Productengine
2023-09-08allow to take snapshot; bind more funcs to call from luaMnikolenko Productengine
2023-09-06addcallback to display error msgMnikolenko Productengine
2023-09-05Initial prototype of embedded LUAMnikolenko Productengine