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/llluamanager.cpp | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'indra/newview/llluamanager.cpp') 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; -- 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/newview/llluamanager.cpp | 25 ------------------------- 1 file changed, 25 deletions(-) (limited to 'indra/newview/llluamanager.cpp') 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 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'indra/newview/llluamanager.cpp') 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()); -- cgit v1.2.3