From ac56718929044e101dc2c7bfe3ebc5dff565b76d Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 28 Jun 2024 13:21:14 -0400 Subject: Add LuaAutorunPath, LuaCommandPath and LuaRequirePath settings. Remove AutorunLuaScriptFile and the LLLUAmanager::runScriptOnLogin() method that checked it. Instead, iterate over LuaAutorunPath directories at viewer startup, iterate over *.lua files in each and implicitly run those. LuaCommandPath and LuaRequirePath are not yet implemented. --- indra/newview/app_settings/settings.xml | 634 +++++++++++++++++--------------- indra/newview/llappviewer.cpp | 19 + indra/newview/llluamanager.cpp | 21 -- indra/newview/llluamanager.h | 2 - indra/newview/llstartup.cpp | 3 - 5 files changed, 350 insertions(+), 329 deletions(-) diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 2463d56eae..cdaf9a47dd 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -346,7 +346,7 @@ Value 0.5 - AudioStreamingMedia + AudioStreamingMedia Comment Enable streaming @@ -1291,7 +1291,7 @@ Type Boolean Value - 0 + 0 CameraPositionSmoothing @@ -1907,17 +1907,17 @@ Value - DebugAvatarRezTime - - Comment - Display times for avatars to resolve. - Persist - 1 - Type - Boolean - Value - 0 - + DebugAvatarRezTime + + Comment + Display times for avatars to resolve. + Persist + 1 + Type + Boolean + Value + 0 + DebugAvatarLocalTexLoadedTime Comment @@ -2292,39 +2292,39 @@ Value 0 - DefaultFemaleAvatar - - Comment - Default Female Avatar - Persist - 1 - Type - String - Value - Female Shape & Outfit - - DefaultLoginLocation - - Comment - Startup destination default (if not specified on command line) - Persist - 0 - Type - String - Value - - - DefaultMaleAvatar - - Comment - Default Male Avatar - Persist - 1 - Type - String - Value - Male Shape & Outfit - + DefaultFemaleAvatar + + Comment + Default Female Avatar + Persist + 1 + Type + String + Value + Female Shape & Outfit + + DefaultLoginLocation + + Comment + Startup destination default (if not specified on command line) + Persist + 0 + Type + String + Value + + + DefaultMaleAvatar + + Comment + Default Male Avatar + Persist + 1 + Type + String + Value + Male Shape & Outfit + DestinationGuideURL Comment @@ -2699,7 +2699,7 @@ Value 0 - FirstSelectedEnabledPopups + FirstSelectedEnabledPopups Comment Return false if there is not enable popup selected in the list of floater preferences popups @@ -3521,39 +3521,39 @@ Value 0 - InventoryLinking - - Comment - Enable ability to create links to folders and items via "Paste as link". - Persist - 1 - Type - Boolean - Value - 1 - - InventoryOutboxLogging - - Comment - Enable debug output associated with the Merchant Outbox. - Persist - 1 - Type - Boolean - Value - 0 - - InventoryOutboxMakeVisible - - Comment - Enable making the Merchant Outbox and Inbox visible in the inventory for debug purposes. - Persist - 1 - Type - Boolean - Value - 0 - + InventoryLinking + + Comment + Enable ability to create links to folders and items via "Paste as link". + Persist + 1 + Type + Boolean + Value + 1 + + InventoryOutboxLogging + + Comment + Enable debug output associated with the Merchant Outbox. + Persist + 1 + Type + Boolean + Value + 0 + + InventoryOutboxMakeVisible + + Comment + Enable making the Merchant Outbox and Inbox visible in the inventory for debug purposes. + Persist + 1 + Type + Boolean + Value + 0 + InventoryOutboxMaxFolderCount Comment @@ -3807,8 +3807,8 @@ Value 0.25 - Jpeg2000AdvancedCompression - + Jpeg2000AdvancedCompression + Comment Use advanced Jpeg2000 compression options (precincts, blocks, ordering, markers) Persist @@ -3817,9 +3817,9 @@ Boolean Value 0 - - Jpeg2000PrecinctsSize - + + Jpeg2000PrecinctsSize + Comment Size of image precincts. Assumed square and same for all levels. Must be power of 2. Persist @@ -3828,9 +3828,9 @@ S32 Value 256 - - Jpeg2000BlocksSize - + + Jpeg2000BlocksSize + Comment Size of encoding blocks. Assumed square and same for all levels. Must be power of 2. Max 64, Min 4. Persist @@ -3839,7 +3839,7 @@ S32 Value 64 - + KeepAspectForSnapshot Comment @@ -3917,10 +3917,23 @@ Value Monospace + LuaAutorunPath + + Comment + Directories containing scripts to autorun at viewer startup + Persist + 1 + Type + LLSD + Value + + scripts/lua/auto + + LuaChunk Comment - Zero or more Lua chunks to run + Zero or more Lua chunks to run from command line Persist 0 Type @@ -3928,10 +3941,36 @@ Value + LuaCommandPath + + Comment + Directories containing scripts recognized as chat slash commands + Persist + 1 + Type + LLSD + Value + + scripts/lua + + + LuaRequirePath + + Comment + Directories containing Lua modules loadable by require() + Persist + 1 + Type + LLSD + Value + + scripts/lua/require + + LuaScript Comment - Zero or more Lua script files to run + Zero or more Lua script files to run from command line Persist 0 Type @@ -4469,17 +4508,17 @@ Value - MarketplaceListingsLogging - - Comment - Enable debug output associated with the Marketplace Listings (SLM) API. - Persist - 1 - Type - Boolean - Value - 0 - + MarketplaceListingsLogging + + Comment + Enable debug output associated with the Marketplace Listings (SLM) API. + Persist + 1 + Type + Boolean + Value + 0 + MarketplaceURL Comment @@ -5365,28 +5404,28 @@ Value 1000 - FakeInitialOutfitName - - Comment - Pretend that this is first time login and specified name was chosen - Persist - 1 - Type + FakeInitialOutfitName + + Comment + Pretend that this is first time login and specified name was chosen + Persist + 1 + Type String Value - - MyOutfitsAutofill - - Comment - Always autofill My Outfits from library when empty (else happens just once). - Persist - 1 - Type - Boolean - Value - 0 - + + MyOutfitsAutofill + + Comment + Always autofill My Outfits from library when empty (else happens just once). + Persist + 1 + Type + Boolean + Value + 0 + NearMeRange Comment @@ -5506,7 +5545,7 @@ Type Boolean Value - 0 + 0 NonvisibleObjectsInMemoryTime @@ -5517,7 +5556,7 @@ Type U32 Value - 64 + 64 NoPreload @@ -6429,7 +6468,7 @@ Value 6.0 - PreferredMaturity + PreferredMaturity Comment Setting for the user's preferred maturity level (consts in indra_constants.h) @@ -6438,7 +6477,7 @@ Type U32 Value - 13 + 13 PreviewAmbientColor @@ -6608,8 +6647,8 @@ PrimMediaMasterEnabled - - Comment + + Comment Whether or not Media on a Prim is enabled. Persist 1 @@ -6618,9 +6657,9 @@ Value 1 - PrimMediaControlsUseHoverControlSet - - Comment + PrimMediaControlsUseHoverControlSet + + Comment Whether or not hovering over prim media uses minimal "hover" controls or the authored control set. Persist 1 @@ -6629,17 +6668,17 @@ Value 0 - PrimMediaDragNDrop - - Comment - Enable drag and drop of URLs onto prim faces - Persist - 1 - Type - Boolean - Value - 1 - + PrimMediaDragNDrop + + Comment + Enable drag and drop of URLs onto prim faces + Persist + 1 + Type + Boolean + Value + 1 + PrimMediaMaxRetries Comment @@ -6673,7 +6712,7 @@ Value 5.0 - PrimMediaMaxSortedQueueSize + PrimMediaMaxSortedQueueSize Comment Maximum number of objects the viewer will load media for initially @@ -6684,7 +6723,7 @@ Value 100000 - PrimMediaMaxRoundRobinQueueSize + PrimMediaMaxRoundRobinQueueSize Comment Maximum number of objects the viewer will continuously update media for @@ -8788,17 +8827,17 @@ Value 1024 - RenderHeroProbeDistance - - Comment - Distance in meters for hero probes to render out to. - Persist - 1 - Type - F32 - Value - 8 - + RenderHeroProbeDistance + + Comment + Distance in meters for hero probes to render out to. + Persist + 1 + Type + F32 + Value + 8 + RenderHeroProbeUpdateRate Comment @@ -9363,17 +9402,17 @@ Value 1 - RenderTransparentWater - - Comment - Render water as transparent. Setting to false renders water as opaque with a simple texture applied. + RenderTransparentWater + + Comment + Render water as transparent. Setting to false renders water as opaque with a simple texture applied. Persist 1 Type Boolean Value 1 - + RenderTreeLODFactor Comment @@ -9655,18 +9694,18 @@ Value 1 - RenderPreferStreamDraw - - Comment - Use GL_STREAM_DRAW in place of GL_DYNAMIC_DRAW - Persist - 1 - Type - Boolean - Value - 0 - - RenderVolumeLODFactor + RenderPreferStreamDraw + + Comment + Use GL_STREAM_DRAW in place of GL_DYNAMIC_DRAW + Persist + 1 + Type + Boolean + Value + 0 + + RenderVolumeLODFactor Comment Controls level of detail of primitives (multiplier for current screen area when calculated level of detail) @@ -9765,18 +9804,18 @@ Value 0 - ReportBugURL - - Comment - URL used for filing bugs from viewer - Persist - 1 - Type - String - Value - https://feedback.secondlife.com/ - - RevokePermsOnStopAnimation + ReportBugURL + + Comment + URL used for filing bugs from viewer + Persist + 1 + Type + String + Value + https://feedback.secondlife.com/ + + RevokePermsOnStopAnimation Comment Clear animation permssions when choosing "Stop Animating Me" @@ -10029,39 +10068,39 @@ Value 400.0 - SceneLoadingMonitorEnabled - - Comment - Enabled scene loading monitor if set - Persist - 0 - Type - Boolean - Value - 0 - - SceneLoadingMonitorSampleTime - - Comment - Time between screen samples when monitor scene load (seconds) - Persist - 1 - Type - F32 - Value - 0.25 - - SceneLoadingMonitorPixelDiffThreshold - - Comment - Amount of pixels changed required to consider the scene as still loading (square root of fraction of pixels on screen) - Persist - 1 - Type - F32 - Value - 0.02 - + SceneLoadingMonitorEnabled + + Comment + Enabled scene loading monitor if set + Persist + 0 + Type + Boolean + Value + 0 + + SceneLoadingMonitorSampleTime + + Comment + Time between screen samples when monitor scene load (seconds) + Persist + 1 + Type + F32 + Value + 0.25 + + SceneLoadingMonitorPixelDiffThreshold + + Comment + Amount of pixels changed required to consider the scene as still loading (square root of fraction of pixels on screen) + Persist + 1 + Type + F32 + Value + 0.02 + ScriptHelpFollowsCursor Comment @@ -10238,7 +10277,7 @@ Value 0 - AvatarNameTagMode + AvatarNameTagMode Comment Select Avatar Name Tag Mode @@ -10447,7 +10486,7 @@ Value 1 - ShowScriptErrors + ShowScriptErrors Comment Show script errors @@ -10458,7 +10497,7 @@ Value 1 - ShowScriptErrorsLocation + ShowScriptErrorsLocation Comment Show script error in chat (0) or window (1). @@ -10717,8 +10756,8 @@ Display results of find events that are flagged as moderate Persist 1 - HideFromEditor - 1 + HideFromEditor + 1 Type Boolean Value @@ -10730,8 +10769,8 @@ Display results of find events that are flagged as adult Persist 1 - HideFromEditor - 1 + HideFromEditor + 1 Type Boolean Value @@ -10743,8 +10782,8 @@ Display results of find land sales that are flagged as general Persist 1 - HideFromEditor - 1 + HideFromEditor + 1 Type Boolean Value @@ -10756,8 +10795,8 @@ Display results of find land sales that are flagged as moderate Persist 1 - HideFromEditor - 1 + HideFromEditor + 1 Type Boolean Value @@ -10769,8 +10808,8 @@ Display results of find land sales that are flagged as adult Persist 1 - HideFromEditor - 1 + HideFromEditor + 1 Type Boolean Value @@ -10782,8 +10821,8 @@ Display results of find places or find popular that are in general sims Persist 1 - HideFromEditor - 1 + HideFromEditor + 1 Type Boolean Value @@ -10795,8 +10834,8 @@ Display results of find places or find popular that are in moderate sims Persist 1 - HideFromEditor - 1 + HideFromEditor + 1 Type Boolean Value @@ -10808,8 +10847,8 @@ Display results of find places or find popular that are in adult sims Persist 1 - HideFromEditor - 1 + HideFromEditor + 1 Type Boolean Value @@ -10947,17 +10986,17 @@ Value 0 - ShowTutorial - - Comment - Show tutorial window on login - Persist - 1 - Type - Boolean - Value - 0 - + ShowTutorial + + Comment + Show tutorial window on login + Persist + 1 + Type + Boolean + Value + 0 + ShowVoiceVisualizersInCalls Comment @@ -13529,17 +13568,17 @@ Value 0.40000000596 - moapbeacon - - Comment - Beacon / Highlight media on a prim sources - Persist - 1 - Type - Boolean - Value - 0 - + moapbeacon + + Comment + Beacon / Highlight media on a prim sources + Persist + 1 + Type + Boolean + Value + 0 + particlesbeacon Comment @@ -13639,17 +13678,17 @@ Value 0 - SLURLDragNDrop - - Comment - Enable drag and drop of SLURLs onto the viewer - Persist - 1 - Type - Boolean - Value - 1 - + SLURLDragNDrop + + Comment + Enable drag and drop of SLURLs onto the viewer + Persist + 1 + Type + Boolean + Value + 1 + SLURLPassToOtherInstance Comment @@ -13837,10 +13876,10 @@ LLSD Value - snapshot - postcard - mini_map - beacons + snapshot + postcard + mini_map + beacons LandmarksSortedByDate @@ -14590,7 +14629,7 @@ Value 0 - LocalTerrainAsset1 + LocalTerrainAsset1 Comment If set to a non-null UUID, overrides the terrain asset locally for all regions with material assets. Local terrain assets are not visible to others. Please keep in mind that this debug setting may be temporary. Do not rely on this setting existing in future viewer builds. @@ -14601,7 +14640,7 @@ Value 00000000-0000-0000-0000-000000000000 - LocalTerrainAsset2 + LocalTerrainAsset2 Comment If set to a non-null UUID, overrides the terrain asset locally for all regions with material assets. Local terrain assets are not visible to others. Please keep in mind that this debug setting may be temporary. Do not rely on this setting existing in future viewer builds. @@ -14612,7 +14651,7 @@ Value 00000000-0000-0000-0000-000000000000 - LocalTerrainAsset3 + LocalTerrainAsset3 Comment If set to a non-null UUID, overrides the terrain asset locally for all regions with material assets. Local terrain assets are not visible to others. Please keep in mind that this debug setting may be temporary. Do not rely on this setting existing in future viewer builds. @@ -14623,7 +14662,7 @@ Value 00000000-0000-0000-0000-000000000000 - LocalTerrainAsset4 + LocalTerrainAsset4 Comment If set to a non-null UUID, overrides the terrain asset locally for all regions with material assets. Local terrain assets are not visible to others. Please keep in mind that this debug setting may be temporary. Do not rely on this setting existing in future viewer builds. @@ -14634,7 +14673,7 @@ Value 00000000-0000-0000-0000-000000000000 - PathfindingRetrieveNeighboringRegion + PathfindingRetrieveNeighboringRegion Comment Download a neighboring region when visualizing a pathfinding navmesh (default val 99 means do not download neighbors). @@ -14643,9 +14682,9 @@ Type U32 Value - 99 + 99 - PathfindingNavMeshClear + PathfindingNavMeshClear Comment Background color when displaying pathfinding navmesh. @@ -14805,7 +14844,7 @@ 1.0 - PathfindingTestPathValidEndColor + PathfindingTestPathValidEndColor Comment Color of the pathfinding test-pathing tool end-point when the path is valid. @@ -14837,7 +14876,7 @@ 1.0 - PathfindingTestPathColor + PathfindingTestPathColor Comment Color of the pathfinding test-path when the path is valid. @@ -15397,17 +15436,6 @@ Value 3 - AutorunLuaScriptName - - Comment - Script name to autorun after login. - Persist - 1 - Type - String - Value - default.lua - ResetUIScaleOnFirstRun Comment @@ -15485,17 +15513,17 @@ Value 300 - StatsReportFileInterval - - Comment - Interval to save viewer stats file data - Persist - 1 - Type - F32 - Value - 0.2 - + StatsReportFileInterval + + Comment + Interval to save viewer stats file data + Persist + 1 + Type + F32 + Value + 0.2 + StatsReportSkipZeroDataSaves Comment diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 65e5e4f783..ef12fe0bd3 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -117,6 +117,7 @@ #include "lldiriterator.h" #include "llexperiencecache.h" #include "llimagej2c.h" +#include "llluamanager.h" #include "llmemory.h" #include "llprimitive.h" #include "llurlaction.h" @@ -1218,6 +1219,24 @@ bool LLAppViewer::init() // no completion callback: we don't need to know LLLUAmanager::runScriptFile(script); }); + processComposeSwitch( + "LuaAutorunPath", "LuaAutorunPath", + [](const LLSD& directory) + { + // each directory can be relative to the viewer's install + // directory -- if directory is already absolute, operator/() + // preserves it + auto abspath(fsyspath(gDirUtilp->getAppRODataDir()) / directory.asString()); + std::string absdir(abspath.string()); + LL_DEBUGS("InitInfo") << "LuaAutorunPath: " << absdir << LL_ENDL; + LLDirIterator scripts(absdir, "*.lua"); + std::string script; + while (scripts.next(script)) + { + LL_DEBUGS("InitInfo") << "LuaAutorunPath: " << absdir << ": " << script << LL_ENDL; + LLLUAmanager::runScriptFile((abspath / script).string()); + } + }); if (gSavedSettings.getBOOL("QAMode") && gSavedSettings.getS32("QAModeEventHostPort") > 0) { diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp index 3ed72c34f3..77f197b2d2 100644 --- a/indra/newview/llluamanager.cpp +++ b/indra/newview/llluamanager.cpp @@ -265,27 +265,6 @@ void LLLUAmanager::runScriptLine(LuaState& L, const std::string& chunk, script_r }); } -void LLLUAmanager::runScriptOnLogin() -{ -#ifndef LL_TEST - std::string filename = gSavedSettings.getString("AutorunLuaScriptName"); - if (filename.empty()) - { - LL_INFOS() << "Script name wasn't set." << LL_ENDL; - return; - } - - filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, filename); - if (!gDirUtilp->fileExists(filename)) - { - LL_INFOS() << filename << " was not found." << LL_ENDL; - return; - } - - runScriptFile(filename); -#endif // ! LL_TEST -} - std::string read_file(const std::string &name) { llifstream in_file; diff --git a/indra/newview/llluamanager.h b/indra/newview/llluamanager.h index af9dcf70c2..dcbb91f799 100644 --- a/indra/newview/llluamanager.h +++ b/indra/newview/llluamanager.h @@ -82,8 +82,6 @@ public: // The return value is the (count, result) pair described above. static std::pair waitScriptLine(LuaState& L, const std::string& chunk); - static void runScriptOnLogin(); - static const std::map getScriptNames() { return sScriptNames; } private: diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp index 470e512694..3cf0def66e 100644 --- a/indra/newview/llstartup.cpp +++ b/indra/newview/llstartup.cpp @@ -208,7 +208,6 @@ #include "llstacktrace.h" #include "threadpool.h" -#include "llluamanager.h" #include "llperfstats.h" @@ -2422,8 +2421,6 @@ bool idle_startup() LLPerfStats::StatsRecorder::setAutotuneInit(); - LLLUAmanager::runScriptOnLogin(); - return TRUE; } -- cgit v1.2.3 From 212868a8c3f803b387da602b6440f69c2c617e40 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 2 Jul 2024 10:35:34 -0400 Subject: Promote LuaRemover from llluamanager.cpp to lua_function.h. --- indra/llcommon/lua_function.h | 34 ++++++++++++++++++++++++++++++++-- indra/newview/llluamanager.cpp | 25 ------------------------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/indra/llcommon/lua_function.h b/indra/llcommon/lua_function.h index c32a586d79..b3b1f40ae5 100644 --- a/indra/llcommon/lua_function.h +++ b/indra/llcommon/lua_function.h @@ -118,11 +118,12 @@ private: * LuaPopper *****************************************************************************/ /** - * LuaPopper is an RAII struct whose role is to pop some number of entries + * LuaPopper is an RAII class whose role is to pop some number of entries * from the Lua stack if the calling function exits early. */ -struct LuaPopper +class LuaPopper { +public: LuaPopper(lua_State* L, int count): mState(L), mCount(count) @@ -136,10 +137,39 @@ struct LuaPopper void disarm() { set(0); } void set(int count) { mCount = count; } +private: lua_State* mState; int mCount; }; +/***************************************************************************** +* LuaRemover +*****************************************************************************/ +/** + * Remove a particular stack index on exit from enclosing scope. + * If you pass a negative index (meaning relative to the current stack top), + * converts to an absolute index. The point of LuaRemover is to remove the + * entry at the specified index regardless of subsequent pushes to the stack. + */ +class LuaRemover +{ +public: + LuaRemover(lua_State* L, int index): + mState(L), + mIndex(lua_absindex(L, index)) + {} + LuaRemover(const LuaRemover&) = delete; + LuaRemover& operator=(const LuaRemover&) = delete; + ~LuaRemover() + { + lua_remove(mState, mIndex); + } + +private: + lua_State* mState; + int mIndex; +}; + /***************************************************************************** * lua_function (and helper class LuaFunction) *****************************************************************************/ diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp index 77f197b2d2..c95ce9c57b 100644 --- a/indra/newview/llluamanager.cpp +++ b/indra/newview/llluamanager.cpp @@ -309,31 +309,6 @@ LLRequireResolver::LLRequireResolver(lua_State *L, const std::string& path) : luaL_argerrorL(L, 1, "cannot require a full path"); } -/** - * Remove a particular stack index on exit from enclosing scope. - * If you pass a negative index (meaning relative to the current stack top), - * converts to an absolute index. The point of LuaRemover is to remove the - * entry at the specified index regardless of subsequent pushes to the stack. - */ -class LuaRemover -{ -public: - LuaRemover(lua_State* L, int index): - mState(L), - mIndex(lua_absindex(L, index)) - {} - LuaRemover(const LuaRemover&) = delete; - LuaRemover& operator=(const LuaRemover&) = delete; - ~LuaRemover() - { - lua_remove(mState, mIndex); - } - -private: - lua_State* mState; - int mIndex; -}; - // push the loaded module or throw a Lua error void LLRequireResolver::findModule() { -- cgit v1.2.3 From f8357732a108e579c285a76a53c550b8b5c0a153 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 2 Jul 2024 12:09:59 -0400 Subject: Make require() implementation honor LuaRequirePath setting. Remove LL_TEST special case from require() code (to search in the viewer's source tree). Instead, make llluamanager_test.cpp append to LuaRequirePath to get the same effect. --- indra/newview/llluamanager.cpp | 18 +++++++---------- indra/newview/tests/llluamanager_test.cpp | 33 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp index c95ce9c57b..ccfa08078e 100644 --- a/indra/newview/llluamanager.cpp +++ b/indra/newview/llluamanager.cpp @@ -32,6 +32,7 @@ #include "llcoros.h" #include "llerror.h" #include "lleventcoro.h" +#include "llsdutil.h" #include "llviewercontrol.h" #include "lua_function.h" #include "lualistener.h" @@ -338,18 +339,13 @@ void LLRequireResolver::findModule() fail(); } - std::vector lib_paths + LLSD lib_paths(gSavedSettings.getLLSD("LuaRequirePath")); + LL_DEBUGS("Lua") << "LuaRequirePath = " << lib_paths << LL_ENDL; + for (const auto& path : llsd::inArray(lib_paths)) { - gDirUtilp->getExpandedFilename(LL_PATH_SCRIPTS, "lua", "require"), -#ifdef LL_TEST - // Build-time tests don't have the app bundle - use source tree. - fsyspath(__FILE__).parent_path() / "scripts" / "lua" / "require", -#endif - }; - - for (const auto& path : lib_paths) - { - std::string absolutePathOpt = (path / mPathToResolve).u8string(); + // if path is already absolute, operator/() preserves it + auto abspath(fsyspath(gDirUtilp->getAppRODataDir()) / path.asString()); + std::string absolutePathOpt = (abspath / mPathToResolve).u8string(); if (absolutePathOpt.empty()) luaL_error(L, "error requiring module '%s'", mPathToResolve.u8string().data()); diff --git a/indra/newview/tests/llluamanager_test.cpp b/indra/newview/tests/llluamanager_test.cpp index d3fc70dfd5..55e87acaea 100644 --- a/indra/newview/tests/llluamanager_test.cpp +++ b/indra/newview/tests/llluamanager_test.cpp @@ -21,6 +21,7 @@ #include "../llcommon/tests/StringVec.h" #include "../test/lltut.h" #include "llapp.h" +#include "llcontrol.h" #include "lldate.h" #include "llevents.h" #include "lleventcoro.h" @@ -39,6 +40,8 @@ public: bool frame() override { return true; } }; +LLControlGroup gSavedSettings("Global"); + template auto listener(CALLABLE&& callable) { @@ -57,6 +60,36 @@ namespace tut { struct llluamanager_data { + llluamanager_data() + { + // Load gSavedSettings from source tree + // indra/newview/tests/llluamanager_test.cpp => + // indra/newview + auto newview{ fsyspath(__FILE__).parent_path().parent_path() }; + auto settings{ newview / "app_settings" / "settings.xml" }; + // true suppresses implicit declare; implicit declare requires + // that every variable in settings.xml has a Comment, which many don't. + gSavedSettings.loadFromFile(settings.u8string().c_str(), true); + // At test time, since we don't have the app bundle available, + // extend LuaRequirePath to include the require directory in the + // source tree. + auto require{ (newview / "scripts" / "lua" / "require").u8string() }; + auto paths{ gSavedSettings.getLLSD("LuaRequirePath") }; + bool found = false; + for (const auto& path : llsd::inArray(paths)) + { + if (path.asString() == require) + { + found = true; + break; + } + } + if (! found) + { + paths.append(require); + gSavedSettings.setLLSD("LuaRequirePath", paths); + } + } // We need an LLApp instance because LLLUAmanager uses coroutines, // which suspend, and when a coroutine suspends it checks LLApp state, // and if it's not APP_STATUS_RUNNING the coroutine terminates. -- cgit v1.2.3 From 9a3c770a3bf430da8878a8691cee9b726a5f026c Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 2 Jul 2024 13:12:40 -0400 Subject: Eliminate c_str() calls from LLControlGroup::loadFromFile() calls. Passing std::string::c_str() to a (const std::string&) function parameter is worse than clutter, it's pointless overhead: it forces the compiler to construct a new std::string instance, instead of passing a const reference to the one you already have in hand. --- indra/llxml/tests/llcontrol_test.cpp | 12 ++++++------ indra/newview/tests/llluamanager_test.cpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/indra/llxml/tests/llcontrol_test.cpp b/indra/llxml/tests/llcontrol_test.cpp index f5f8b285f7..595c6a600b 100644 --- a/indra/llxml/tests/llcontrol_test.cpp +++ b/indra/llxml/tests/llcontrol_test.cpp @@ -97,7 +97,7 @@ namespace tut template<> template<> void control_group_t::test<1>() { - int results = mCG->loadFromFile(mTestConfigFile.c_str()); + int results = mCG->loadFromFile(mTestConfigFile); ensure("number of settings", (results == 1)); ensure("value of setting", (mCG->getU32("TestSetting") == 12)); } @@ -106,14 +106,14 @@ namespace tut template<> template<> void control_group_t::test<2>() { - int results = mCG->loadFromFile(mTestConfigFile.c_str()); + int results = mCG->loadFromFile(mTestConfigFile); mCG->setU32("TestSetting", 13); ensure_equals("value of changed setting", mCG->getU32("TestSetting"), 13); LLControlGroup test_cg("foo2"); std::string temp_test_file = (mTestConfigDir + "setting_llsd_temp.xml"); mCleanups.push_back(temp_test_file); mCG->saveToFile(temp_test_file.c_str(), TRUE); - results = test_cg.loadFromFile(temp_test_file.c_str()); + results = test_cg.loadFromFile(temp_test_file); ensure("number of changed settings loaded", (results == 1)); ensure("value of changed settings loaded", (test_cg.getU32("TestSetting") == 13)); } @@ -126,7 +126,7 @@ namespace tut // a default settings file that declares variables, rather than a user // settings file. When loadFromFile() encounters an unrecognized user // settings variable, it forcibly preserves it (CHOP-962). - int results = mCG->loadFromFile(mTestConfigFile.c_str(), true); + int results = mCG->loadFromFile(mTestConfigFile, true); LLControlVariable* control = mCG->getControl("TestSetting"); LLSD new_value = 13; control->setValue(new_value, FALSE); @@ -135,7 +135,7 @@ namespace tut std::string temp_test_file = (mTestConfigDir + "setting_llsd_persist_temp.xml"); mCleanups.push_back(temp_test_file); mCG->saveToFile(temp_test_file.c_str(), TRUE); - results = test_cg.loadFromFile(temp_test_file.c_str()); + results = test_cg.loadFromFile(temp_test_file); //If we haven't changed any settings, then we shouldn't have any settings to load ensure("number of non-persisted changed settings loaded", (results == 0)); } @@ -144,7 +144,7 @@ namespace tut template<> template<> void control_group_t::test<4>() { - int results = mCG->loadFromFile(mTestConfigFile.c_str()); + int results = mCG->loadFromFile(mTestConfigFile); ensure("number of settings", (results == 1)); mCG->getControl("TestSetting")->getSignal()->connect(boost::bind(&this->handleListenerTest)); mCG->setU32("TestSetting", 13); diff --git a/indra/newview/tests/llluamanager_test.cpp b/indra/newview/tests/llluamanager_test.cpp index 55e87acaea..824ddd445b 100644 --- a/indra/newview/tests/llluamanager_test.cpp +++ b/indra/newview/tests/llluamanager_test.cpp @@ -69,7 +69,7 @@ namespace tut auto settings{ newview / "app_settings" / "settings.xml" }; // true suppresses implicit declare; implicit declare requires // that every variable in settings.xml has a Comment, which many don't. - gSavedSettings.loadFromFile(settings.u8string().c_str(), true); + gSavedSettings.loadFromFile(settings.u8string(), true); // At test time, since we don't have the app bundle available, // extend LuaRequirePath to include the require directory in the // source tree. -- cgit v1.2.3