From 36f535a8ec1dc2d2553a322259a28e42aff5940b Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 9 Feb 2024 17:19:39 -0500 Subject: Make LLLUAmanager::runScriptFile() use filename as description. Since the description shows up in the log output, it's better to see just the script filename than to see "runScriptFile('filename')". --- indra/newview/llluamanager.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp index c55c44e671..d58ee5ca5f 100644 --- a/indra/newview/llluamanager.cpp +++ b/indra/newview/llluamanager.cpp @@ -300,8 +300,7 @@ std::pair LLLUAmanager::waitScriptFile(LuaState& L, const std::string void LLLUAmanager::runScriptFile(LuaState& L, const std::string& filename, script_result_fn cb) { - std::string desc{ stringize("runScriptFile('", filename, "')") }; - LLCoros::instance().launch(desc, [&L, desc, filename, cb]() + LLCoros::instance().launch(filename, [&L, filename, cb]() { llifstream in_file; in_file.open(filename.c_str()); @@ -310,7 +309,7 @@ void LLLUAmanager::runScriptFile(LuaState& L, const std::string& filename, scrip { std::string text{std::istreambuf_iterator(in_file), std::istreambuf_iterator()}; - auto [count, result] = L.expr(desc, text); + auto [count, result] = L.expr(filename, text); if (cb) { cb(count, result); -- cgit v1.2.3 From 177000d2c9b3dba889119d63109f9b6d8748b0b7 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 9 Feb 2024 17:19:48 -0500 Subject: Add command-line switches --lua "chunk" and --luafile pathname. --lua "chunk" runs the specified Lua chunk at startup time. --luafile pathname runs the specified Lua script file at startup time. You may specify more than one --lua or --luafile switch on the command line. --- indra/newview/app_settings/cmd_line.xml | 28 ++++++++++++++- indra/newview/app_settings/settings.xml | 24 ++++++++++++- indra/newview/llappviewer.cpp | 60 +++++++++++++++++++++++---------- 3 files changed, 93 insertions(+), 19 deletions(-) diff --git a/indra/newview/app_settings/cmd_line.xml b/indra/newview/app_settings/cmd_line.xml index 340334aee8..534d1d594d 100644 --- a/indra/newview/app_settings/cmd_line.xml +++ b/indra/newview/app_settings/cmd_line.xml @@ -195,7 +195,33 @@ LogPerformance - multiple + lua + + desc + Run specified Lua chunk + count + 1 + + compose + true + map-to + LuaChunk + + + luafile + + desc + Run specified Lua script + count + 1 + + compose + true + map-to + LuaScript + + + multiple desc Allow multiple viewers. diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 5e4cd4e57b..bda07f8821 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -68,7 +68,7 @@ Value 1 - CrashHostUrl + CrashHostUrl Comment A URL pointing to a crash report handler; overrides cluster negotiation to locate crash handler. @@ -5431,6 +5431,28 @@ Value http://wiki.secondlife.com/wiki/[LSL_STRING] + LuaChunk + + Comment + Zero or more Lua chunks to run + Persist + 0 + Type + LLSD + Value + + + LuaScript + + Comment + Zero or more Lua script files to run + Persist + 0 + Type + LLSD + Value + + GridStatusRSS Comment diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 4a43133ff6..5ad6f1dc1e 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -60,6 +60,7 @@ #include "llslurl.h" #include "llstartup.h" #include "llfocusmgr.h" +#include "llluamanager.h" #include "llurlfloaterdispatchhandler.h" #include "llviewerjoystick.h" #include "llallocator.h" @@ -386,6 +387,9 @@ static std::string gLaunchFileOnQuit; // Used on Win32 for other apps to identify our window (eg, win_setup) const char* const VIEWER_WINDOW_CLASSNAME = "Second Life"; +void processComposeSwitch(const std::string&, const std::string&, + const std::function&); + //---------------------------------------------------------------------------- // List of entries from strings.xml to always replace @@ -1194,22 +1198,10 @@ bool LLAppViewer::init() } #endif //LL_RELEASE_FOR_DOWNLOAD - { - // Iterate over --leap command-line options. But this is a bit tricky: if - // there's only one, it won't be an array at all. - LLSD LeapCommand(gSavedSettings.getLLSD("LeapCommand")); - LL_DEBUGS("InitInfo") << "LeapCommand: " << LeapCommand << LL_ENDL; - if (LeapCommand.isDefined() && !LeapCommand.isArray()) - { - // If LeapCommand is actually a scalar value, make an array of it. - // Have to do it in two steps because LeapCommand.append(LeapCommand) - // trashes content! :-P - LLSD item(LeapCommand); - LeapCommand.append(item); - } - BOOST_FOREACH(const std::string& leap, llsd::inArray(LeapCommand)) + processComposeSwitch( + "--leap", "LeapCommand", + [](const LLSD& leap) { - LL_INFOS("InitInfo") << "processing --leap \"" << leap << '"' << LL_ENDL; // We don't have any better description of this plugin than the // user-specified command line. Passing "" causes LLLeap to derive a // description from the command line itself. @@ -1217,8 +1209,21 @@ bool LLAppViewer::init() // don't consider any one --leap command mission-critical, so if one // fails, log it, shrug and carry on. LLLeap::create("", leap, false); // exception=false - } - } + }); + processComposeSwitch( + "--lua", "LuaChunk", + [](const LLSD& chunk) + { + // no completion callback: we don't need to know + LLLUAmanager::runScriptLine(chunk); + }); + processComposeSwitch( + "--luafile", "LuaScript", + [](const LLSD& script) + { + // no completion callback: we don't need to know + LLLUAmanager::runScriptFile(script); + }); if (gSavedSettings.getBOOL("QAMode") && gSavedSettings.getS32("QAModeEventHostPort") > 0) { @@ -1291,6 +1296,27 @@ bool LLAppViewer::init() return true; } +void processComposeSwitch(const std::string& option, + const std::string& setting, + const std::function& action) +{ + // Iterate over 'option' command-line options. But this is a bit tricky: + // if there's only one, it won't be an array at all. + LLSD args(gSavedSettings.getLLSD(setting)); + LL_DEBUGS("InitInfo") << option << ": " << args << LL_ENDL; + if (args.isDefined() && ! args.isArray()) + { + // If args is actually a scalar value, make an array of it. Have to do + // it in two steps because args.append(args) trashes content! :-P + args.append(LLSD(args)); + } + for (const auto& arg : llsd::inArray(args)) + { + LL_INFOS("InitInfo") << "processing " << option << ' ' << arg << LL_ENDL; + action(arg); + } +} + void LLAppViewer::initMaxHeapSize() { //set the max heap size. -- cgit v1.2.3