summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2023-09-28 09:40:09 -0400
committerNat Goodspeed <nat@lindenlab.com>2023-09-28 09:40:09 -0400
commit7fccd662df48e5ddef0ec7e14a43289024bd27e1 (patch)
treeb8d0bc3c9f6774c77e157cf6d73e13e5a20af799 /indra/newview
parent6a3bb72620ccefe316e9c011df5191f7a16f358c (diff)
DRTVWR-589: Try to override Lua's built-in print() with print_info()
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.
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/llluamanager.cpp46
1 files changed, 27 insertions, 19 deletions
diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp
index c1e111f0ac..931faadf4b 100644
--- a/indra/newview/llluamanager.cpp
+++ b/indra/newview/llluamanager.cpp
@@ -226,6 +226,15 @@ public:
}
}
+ static lua_CFunction get(const std::string& key)
+ {
+ // use find() instead of subscripting to avoid creating an entry for
+ // unknown key
+ const auto& registry{ getRegistry() };
+ auto found{ registry.find(key) };
+ return (found == registry.end())? nullptr : found->second;
+ }
+
private:
using Registry = std::map<std::string, lua_CFunction>;
static Registry& getRegistry()
@@ -668,11 +677,6 @@ lua_function(listen_events)
return 2;
}
-void initLUA(lua_State *L)
-{
- LuaFunction::init(L);
-}
-
/**
* RAII class to manage the lifespan of a lua_State
*/
@@ -685,7 +689,9 @@ public:
mState(luaL_newstate())
{
luaL_openlibs(mState);
- initLUA(mState);
+ LuaFunction::init(mState);
+ // Try to make print() write to our log.
+ lua_register(mState, "print", LuaFunction::get("print_info"));
}
LuaState(const LuaState&) = delete;
@@ -747,9 +753,10 @@ private:
void LLLUAmanager::runScriptFile(const std::string& filename, script_finished_fn cb)
{
- LLCoros::instance().launch("LUAScriptFileCoro", [filename, cb]()
+ std::string desc{ stringize("runScriptFile('", filename, "')") };
+ LLCoros::instance().launch(desc, [desc, filename, cb]()
{
- LuaState L(stringize("runScriptFile('", filename, "')"), cb);
+ LuaState L(desc, cb);
auto LUA_sleep_func = [](lua_State *L)
{
@@ -776,18 +783,19 @@ void LLLUAmanager::runScriptFile(const std::string& filename, script_finished_fn
void LLLUAmanager::runScriptLine(const std::string& cmd, script_finished_fn cb)
{
- LLCoros::instance().launch("LUAScriptFileCoro", [cmd, cb]()
+ // find a suitable abbreviation for the cmd string
+ std::string_view shortcmd{ cmd };
+ const size_t shortlen = 40;
+ std::string::size_type eol = shortcmd.find_first_of("\r\n");
+ if (eol != std::string::npos)
+ shortcmd = shortcmd.substr(0, eol);
+ if (shortcmd.length() > shortlen)
+ shortcmd = stringize(shortcmd.substr(0, shortlen), "...");
+
+ std::string desc{ stringize("runScriptLine('", shortcmd, "')") };
+ LLCoros::instance().launch(desc, [desc, cmd, cb]()
{
- // find a suitable abbreviation for the cmd string
- std::string_view shortcmd{ cmd };
- const size_t shortlen = 40;
- std::string::size_type eol = shortcmd.find_first_of("\r\n");
- if (eol != std::string::npos)
- shortcmd = shortcmd.substr(0, eol);
- if (shortcmd.length() > shortlen)
- shortcmd = stringize(shortcmd.substr(0, shortlen), "...");
-
- LuaState L(stringize("runScriptLine('", shortcmd, "')"), cb);
+ LuaState L(desc, cb);
L.checkLua(luaL_dostring(L, cmd.c_str()));
});
}