From 836f8dc26f2041aea51c5c953b99f34859db6387 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Mon, 1 Apr 2024 13:13:53 +0300 Subject: Add 'Lua Scripts' floater --- indra/llwindow/llwindow.h | 2 + indra/llwindow/llwindowmacosx.h | 2 + indra/llwindow/llwindowwin32.cpp | 39 ++++--- indra/llwindow/llwindowwin32.h | 2 + indra/newview/CMakeLists.txt | 2 + indra/newview/llfloaterluascripts.cpp | 123 +++++++++++++++++++++ indra/newview/llfloaterluascripts.h | 55 +++++++++ indra/newview/llluamanager.cpp | 5 + indra/newview/llluamanager.h | 5 + indra/newview/llviewerfloaterreg.cpp | 2 + .../skins/default/xui/en/floater_lua_scripts.xml | 36 ++++++ .../skins/default/xui/en/menu_lua_scripts.xml | 11 ++ indra/newview/skins/default/xui/en/menu_viewer.xml | 10 ++ 13 files changed, 279 insertions(+), 15 deletions(-) create mode 100644 indra/newview/llfloaterluascripts.cpp create mode 100644 indra/newview/llfloaterluascripts.h create mode 100644 indra/newview/skins/default/xui/en/floater_lua_scripts.xml create mode 100644 indra/newview/skins/default/xui/en/menu_lua_scripts.xml diff --git a/indra/llwindow/llwindow.h b/indra/llwindow/llwindow.h index f435d46584..9e9e424455 100644 --- a/indra/llwindow/llwindow.h +++ b/indra/llwindow/llwindow.h @@ -187,6 +187,8 @@ public: virtual void interruptLanguageTextInput() {} virtual void spawnWebBrowser(const std::string& escaped_url, bool async) {}; + virtual void openFolder(const std::string &path) {}; + static std::vector getDynamicFallbackFontList(); // Provide native key event data diff --git a/indra/llwindow/llwindowmacosx.h b/indra/llwindow/llwindowmacosx.h index 7614167213..5f728fb72e 100644 --- a/indra/llwindow/llwindowmacosx.h +++ b/indra/llwindow/llwindowmacosx.h @@ -116,6 +116,8 @@ public: void spawnWebBrowser(const std::string& escaped_url, bool async) override; F32 getSystemUISize() override; + void openFolder(const std::string &path) override; + static std::vector getDisplaysResolutionList(); static std::vector getDynamicFallbackFontList(); diff --git a/indra/llwindow/llwindowwin32.cpp b/indra/llwindow/llwindowwin32.cpp index 057d7a700e..e3ef28a27d 100644 --- a/indra/llwindow/llwindowwin32.cpp +++ b/indra/llwindow/llwindowwin32.cpp @@ -3755,6 +3755,25 @@ S32 OSMessageBoxWin32(const std::string& text, const std::string& caption, U32 t return retval; } +void shell_open(const std::string &file, bool async) +{ + // this is madness.. no, this is.. + LLWString url_wstring = utf8str_to_wstring(file); + llutf16string url_utf16 = wstring_to_utf16str(url_wstring); + + // let the OS decide what to use to open the URL + SHELLEXECUTEINFO sei = {sizeof(sei)}; + // NOTE: this assumes that SL will stick around long enough to complete the DDE message exchange + // necessary for ShellExecuteEx to complete + if (async) + { + sei.fMask = SEE_MASK_ASYNCOK; + } + sei.nShow = SW_SHOWNORMAL; + sei.lpVerb = L"open"; + sei.lpFile = url_utf16.c_str(); + ShellExecuteEx(&sei); +} void LLWindowWin32::spawnWebBrowser(const std::string& escaped_url, bool async) { @@ -3780,22 +3799,12 @@ void LLWindowWin32::spawnWebBrowser(const std::string& escaped_url, bool async) // replaced ShellExecute code with ShellExecuteEx since ShellExecute doesn't work // reliablly on Vista. - // this is madness.. no, this is.. - LLWString url_wstring = utf8str_to_wstring( escaped_url ); - llutf16string url_utf16 = wstring_to_utf16str( url_wstring ); + shell_open(escaped_url, async); +} - // let the OS decide what to use to open the URL - SHELLEXECUTEINFO sei = { sizeof( sei ) }; - // NOTE: this assumes that SL will stick around long enough to complete the DDE message exchange - // necessary for ShellExecuteEx to complete - if (async) - { - sei.fMask = SEE_MASK_ASYNCOK; - } - sei.nShow = SW_SHOWNORMAL; - sei.lpVerb = L"open"; - sei.lpFile = url_utf16.c_str(); - ShellExecuteEx( &sei ); +void LLWindowWin32::openFolder(const std::string &path) +{ + shell_open(path, false); } /* diff --git a/indra/llwindow/llwindowwin32.h b/indra/llwindow/llwindowwin32.h index ff287a140e..ed64891108 100644 --- a/indra/llwindow/llwindowwin32.h +++ b/indra/llwindow/llwindowwin32.h @@ -122,6 +122,8 @@ public: /*virtual*/ void interruptLanguageTextInput(); /*virtual*/ void spawnWebBrowser(const std::string& escaped_url, bool async); + void openFolder(const std::string &path); + /*virtual*/ F32 getSystemUISize(); LLWindowCallbacks::DragNDropResult completeDragNDropRequest( const LLCoordGL gl_coord, const MASK mask, LLWindowCallbacks::DragNDropAction action, const std::string url ); diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index b26ce7d06d..f41e481b26 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -243,6 +243,7 @@ set(viewer_SOURCE_FILES llfloaterlinkreplace.cpp llfloaterloadprefpreset.cpp llfloaterluadebug.cpp + llfloaterluascripts.cpp llfloatermarketplacelistings.cpp llfloatermap.cpp llfloatermediasettings.cpp @@ -901,6 +902,7 @@ set(viewer_HEADER_FILES llfloaterlinkreplace.h llfloaterloadprefpreset.h llfloaterluadebug.h + llfloaterluascripts.h llfloatermap.h llfloatermarketplacelistings.h llfloatermediasettings.h diff --git a/indra/newview/llfloaterluascripts.cpp b/indra/newview/llfloaterluascripts.cpp new file mode 100644 index 0000000000..87d2cf0c69 --- /dev/null +++ b/indra/newview/llfloaterluascripts.cpp @@ -0,0 +1,123 @@ +/** + * @file llfloaterluascriptsinfo.cpp + * + * $LicenseInfo:firstyear=2024&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2024, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" + +#include "llfloaterluascripts.h" +#include "llevents.h" +#include +#include "llluamanager.h" +#include "llscrolllistctrl.h" +#include "llviewerwindow.h" +#include "llwindow.h" +#include "llviewermenu.h" + +const F32 REFRESH_INTERVAL = 1.0f; + +LLFloaterLUAScripts::LLFloaterLUAScripts(const LLSD &key) + : LLFloater(key), + mUpdateTimer(new LLTimer()), + mContextMenuHandle() +{ + mCommitCallbackRegistrar.add("Script.OpenFolder", [this](LLUICtrl*, const LLSD &userdata) + { + gViewerWindow->getWindow()->openFolder(mTargetFolderPath); + }); +} + + +BOOL LLFloaterLUAScripts::postBuild() +{ + mScriptList = getChild("scripts_list"); + mScriptList->setRightMouseDownCallback(boost::bind(&LLFloaterLUAScripts::onScrollListRightClicked, this, _1, _2, _3)); + + LLContextMenu *menu = LLUICtrlFactory::getInstance()->createFromFile( + "menu_lua_scripts.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); + if (menu) + { + mContextMenuHandle = menu->getHandle(); + } + + return TRUE; +} + +LLFloaterLUAScripts::~LLFloaterLUAScripts() +{ + auto menu = mContextMenuHandle.get(); + if (menu) + { + menu->die(); + mContextMenuHandle.markDead(); + } + + delete mUpdateTimer; +} + +void LLFloaterLUAScripts::draw() +{ + if (mUpdateTimer->hasExpired()) + { + populateScriptList(); + } + LLFloater::draw(); +} + +void LLFloaterLUAScripts::populateScriptList() +{ + S32 prev_pos = mScriptList->getScrollPos(); + LLSD prev_selected = mScriptList->getSelectedValue(); + mScriptList->clearRows(); + mScriptList->updateColumns(true); + std::map scripts = LLLUAmanager::getScriptNames(); + for (auto &it : scripts) + { + LLSD row; + row["value"] = it.first; + row["columns"][0]["value"] = std::filesystem::path((it.second)).stem().string(); + row["columns"][0]["column"] = "script_name"; + row["columns"][1]["value"] = it.second; + row["columns"][1]["column"] = "script_path"; + mScriptList->addElement(row); + } + mScriptList->setScrollPos(prev_pos); + mScriptList->setSelectedByValue(prev_selected, true); + mUpdateTimer->setTimerExpirySec(REFRESH_INTERVAL); +} + +void LLFloaterLUAScripts::onScrollListRightClicked(LLUICtrl *ctrl, S32 x, S32 y) +{ + LLScrollListItem *item = mScriptList->hitItem(x, y); + if (item) + { + mScriptList->selectItemAt(x, y, MASK_NONE); + auto menu = mContextMenuHandle.get(); + if (menu) + { + mTargetFolderPath = std::filesystem::path((item->getColumn(1)->getValue().asString())).parent_path().string(); + menu->show(x, y); + LLMenuGL::showPopup(this, menu, x, y); + } + } +} diff --git a/indra/newview/llfloaterluascripts.h b/indra/newview/llfloaterluascripts.h new file mode 100644 index 0000000000..c8c9e7f020 --- /dev/null +++ b/indra/newview/llfloaterluascripts.h @@ -0,0 +1,55 @@ +/** + * @file llfloaterluascriptsinfo.h + * + * $LicenseInfo:firstyear=2024&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2024, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLFLOATERLUASCRIPTS_H +#define LL_LLFLOATERLUASCRIPTS_H + +#include "llfloater.h" + +class LLScrollListCtrl; + +class LLFloaterLUAScripts : + public LLFloater +{ + public: + LLFloaterLUAScripts(const LLSD &key); + virtual ~LLFloaterLUAScripts(); + + BOOL postBuild(); + void draw(); + +private: + void populateScriptList(); + void onScrollListRightClicked(LLUICtrl *ctrl, S32 x, S32 y); + + LLTimer* mUpdateTimer; + LLScrollListCtrl* mScriptList; + std::string mTargetFolderPath; + + LLHandle mContextMenuHandle; +}; + +#endif // LL_LLFLOATERLUASCRIPTS_H + diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp index be332a7244..343c7c7459 100644 --- a/indra/newview/llluamanager.cpp +++ b/indra/newview/llluamanager.cpp @@ -48,6 +48,8 @@ #include #include +std::map LLLUAmanager::sScriptNames; + lua_function(sleep, "sleep(seconds): pause the running coroutine") { F32 seconds = lua_tonumber(L, -1); @@ -177,6 +179,8 @@ void LLLUAmanager::runScriptFile(const std::string &filename, script_result_fn r // A script_result_fn will be called when LuaState::expr() completes. LLCoros::instance().launch(filename, [filename, result_cb, finished_cb]() { + std::string coro_name = LLCoros::getName(); + sScriptNames[coro_name] = filename; llifstream in_file; in_file.open(filename.c_str()); @@ -201,6 +205,7 @@ void LLLUAmanager::runScriptFile(const std::string &filename, script_result_fn r result_cb(-1, msg); } } + sScriptNames.erase(coro_name); }); } diff --git a/indra/newview/llluamanager.h b/indra/newview/llluamanager.h index a297d14502..70728f958e 100644 --- a/indra/newview/llluamanager.h +++ b/indra/newview/llluamanager.h @@ -80,6 +80,11 @@ public: static std::pair waitScriptLine(LuaState& L, const std::string& chunk); static void runScriptOnLogin(); + + static std::map getScriptNames() { return sScriptNames; } + + private: + static std::map sScriptNames; }; class LLRequireResolver diff --git a/indra/newview/llviewerfloaterreg.cpp b/indra/newview/llviewerfloaterreg.cpp index f72ef71241..de328639f8 100644 --- a/indra/newview/llviewerfloaterreg.cpp +++ b/indra/newview/llviewerfloaterreg.cpp @@ -94,6 +94,7 @@ #include "llfloaterlinkreplace.h" #include "llfloaterloadprefpreset.h" #include "llfloaterluadebug.h" +#include "llfloaterluascripts.h" #include "llfloatermap.h" #include "llfloatermarketplacelistings.h" #include "llfloatermediasettings.h" @@ -402,6 +403,7 @@ void LLViewerFloaterReg::registerFloaters() LLFloaterReg::add("load_pref_preset", "floater_load_pref_preset.xml", (LLFloaterBuildFunc)&LLFloaterReg::build); LLFloaterReg::add("lua_debug", "floater_lua_debug.xml", (LLFloaterBuildFunc) &LLFloaterReg::build); + LLFloaterReg::add("lua_scripts", "floater_lua_scripts.xml", (LLFloaterBuildFunc) &LLFloaterReg::build); LLFloaterReg::add("mem_leaking", "floater_mem_leaking.xml", (LLFloaterBuildFunc)&LLFloaterReg::build); diff --git a/indra/newview/skins/default/xui/en/floater_lua_scripts.xml b/indra/newview/skins/default/xui/en/floater_lua_scripts.xml new file mode 100644 index 0000000000..6859201650 --- /dev/null +++ b/indra/newview/skins/default/xui/en/floater_lua_scripts.xml @@ -0,0 +1,36 @@ + + + + + + + diff --git a/indra/newview/skins/default/xui/en/menu_lua_scripts.xml b/indra/newview/skins/default/xui/en/menu_lua_scripts.xml new file mode 100644 index 0000000000..8f718abe17 --- /dev/null +++ b/indra/newview/skins/default/xui/en/menu_lua_scripts.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/indra/newview/skins/default/xui/en/menu_viewer.xml b/indra/newview/skins/default/xui/en/menu_viewer.xml index b259b101b4..40f5c40dfe 100644 --- a/indra/newview/skins/default/xui/en/menu_viewer.xml +++ b/indra/newview/skins/default/xui/en/menu_viewer.xml @@ -2539,6 +2539,16 @@ function="World.EnvPreset" function="Floater.Toggle" parameter="lua_debug" /> + + + + Date: Mon, 1 Apr 2024 15:33:15 +0300 Subject: open folder support for mac --- indra/llwindow/llwindowmacosx-objc.h | 2 ++ indra/llwindow/llwindowmacosx-objc.mm | 7 +++++++ indra/llwindow/llwindowmacosx.cpp | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 77024d3a9c..ade303c6d4 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -177,6 +177,8 @@ void setMarkedText(unsigned short *text, unsigned int *selectedRange, unsigned i void getPreeditLocation(float *location, unsigned int length); void allowDirectMarkedTextInput(bool allow, GLViewRef glView); +void openFolderWithFinder(const char *folder_path); + NSWindowRef getMainAppWindow(); GLViewRef getGLView(); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 690fe058db..56d1798dcf 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -462,6 +462,13 @@ long showAlert(std::string text, std::string title, int type) return ret; } +void openFolderWithFinder(const char *folder_path) +{ + @autoreleasepool { + NSString *folderPathString = [NSString stringWithUTF8String:folder_path]; + [[NSWorkspace sharedWorkspace] openFile:folderPathString withApplication:@"Finder"]; + } +} /* GLViewRef getGLView() { diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 778e5d3898..b774597eb6 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -2076,6 +2076,11 @@ F32 LLWindowMacOSX::getSystemUISize() return gHiDPISupport ? ::getDeviceUnitSize(mGLView) : LLWindow::getSystemUISize(); } +void LLWindowMacOSX::openFolder(const std::string &path) +{ + openFolderWithFinder(path.c_str()); +} + #if LL_OS_DRAGDROP_ENABLED /* S16 LLWindowMacOSX::dragTrackingHandler(DragTrackingMessage message, WindowRef theWindow, -- cgit v1.2.3 From b351888ed7d395279dfc022363e911d52ebdcc16 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Wed, 3 Apr 2024 14:26:34 +0300 Subject: Add RAII class for adding/erasing script entries; code clean up --- indra/llwindow/llwindowwin32.cpp | 4 +--- indra/llwindow/llwindowwin32.h | 2 +- indra/newview/llfloaterluascripts.cpp | 7 ++----- indra/newview/llfloaterluascripts.h | 2 +- indra/newview/llluamanager.cpp | 4 +--- indra/newview/llluamanager.h | 18 +++++++++++++++++- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/indra/llwindow/llwindowwin32.cpp b/indra/llwindow/llwindowwin32.cpp index e3ef28a27d..7fbc2c8ea2 100644 --- a/indra/llwindow/llwindowwin32.cpp +++ b/indra/llwindow/llwindowwin32.cpp @@ -3757,9 +3757,7 @@ S32 OSMessageBoxWin32(const std::string& text, const std::string& caption, U32 t void shell_open(const std::string &file, bool async) { - // this is madness.. no, this is.. - LLWString url_wstring = utf8str_to_wstring(file); - llutf16string url_utf16 = wstring_to_utf16str(url_wstring); + std::wstring url_utf16 = ll_convert(file); // let the OS decide what to use to open the URL SHELLEXECUTEINFO sei = {sizeof(sei)}; diff --git a/indra/llwindow/llwindowwin32.h b/indra/llwindow/llwindowwin32.h index ed64891108..320c1c8b88 100644 --- a/indra/llwindow/llwindowwin32.h +++ b/indra/llwindow/llwindowwin32.h @@ -122,7 +122,7 @@ public: /*virtual*/ void interruptLanguageTextInput(); /*virtual*/ void spawnWebBrowser(const std::string& escaped_url, bool async); - void openFolder(const std::string &path); + void openFolder(const std::string &path) override; /*virtual*/ F32 getSystemUISize(); diff --git a/indra/newview/llfloaterluascripts.cpp b/indra/newview/llfloaterluascripts.cpp index 87d2cf0c69..bd845a97d6 100644 --- a/indra/newview/llfloaterluascripts.cpp +++ b/indra/newview/llfloaterluascripts.cpp @@ -51,7 +51,7 @@ LLFloaterLUAScripts::LLFloaterLUAScripts(const LLSD &key) BOOL LLFloaterLUAScripts::postBuild() { mScriptList = getChild("scripts_list"); - mScriptList->setRightMouseDownCallback(boost::bind(&LLFloaterLUAScripts::onScrollListRightClicked, this, _1, _2, _3)); + mScriptList->setRightMouseDownCallback([this](LLUICtrl *ctrl, S32 x, S32 y, MASK mask) { onScrollListRightClicked(ctrl, x, y);}); LLContextMenu *menu = LLUICtrlFactory::getInstance()->createFromFile( "menu_lua_scripts.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); @@ -71,13 +71,11 @@ LLFloaterLUAScripts::~LLFloaterLUAScripts() menu->die(); mContextMenuHandle.markDead(); } - - delete mUpdateTimer; } void LLFloaterLUAScripts::draw() { - if (mUpdateTimer->hasExpired()) + if (mUpdateTimer->checkExpirationAndReset(REFRESH_INTERVAL)) { populateScriptList(); } @@ -103,7 +101,6 @@ void LLFloaterLUAScripts::populateScriptList() } mScriptList->setScrollPos(prev_pos); mScriptList->setSelectedByValue(prev_selected, true); - mUpdateTimer->setTimerExpirySec(REFRESH_INTERVAL); } void LLFloaterLUAScripts::onScrollListRightClicked(LLUICtrl *ctrl, S32 x, S32 y) diff --git a/indra/newview/llfloaterluascripts.h b/indra/newview/llfloaterluascripts.h index c8c9e7f020..548bbd10f6 100644 --- a/indra/newview/llfloaterluascripts.h +++ b/indra/newview/llfloaterluascripts.h @@ -44,7 +44,7 @@ private: void populateScriptList(); void onScrollListRightClicked(LLUICtrl *ctrl, S32 x, S32 y); - LLTimer* mUpdateTimer; + std::unique_ptr mUpdateTimer; LLScrollListCtrl* mScriptList; std::string mTargetFolderPath; diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp index 343c7c7459..d2b8ca3a94 100644 --- a/indra/newview/llluamanager.cpp +++ b/indra/newview/llluamanager.cpp @@ -179,8 +179,7 @@ void LLLUAmanager::runScriptFile(const std::string &filename, script_result_fn r // A script_result_fn will be called when LuaState::expr() completes. LLCoros::instance().launch(filename, [filename, result_cb, finished_cb]() { - std::string coro_name = LLCoros::getName(); - sScriptNames[coro_name] = filename; + ScriptObserver observer(LLCoros::getName(), filename); llifstream in_file; in_file.open(filename.c_str()); @@ -205,7 +204,6 @@ void LLLUAmanager::runScriptFile(const std::string &filename, script_result_fn r result_cb(-1, msg); } } - sScriptNames.erase(coro_name); }); } diff --git a/indra/newview/llluamanager.h b/indra/newview/llluamanager.h index 70728f958e..88467cbf84 100644 --- a/indra/newview/llluamanager.h +++ b/indra/newview/llluamanager.h @@ -40,6 +40,8 @@ class LuaState; class LLLUAmanager { + friend class ScriptObserver; + public: // Pass a callback with this signature to obtain the error message, if // any, from running a script or source string. Empty msg means success. @@ -81,7 +83,7 @@ public: static void runScriptOnLogin(); - static std::map getScriptNames() { return sScriptNames; } + static const std::map getScriptNames() { return sScriptNames; } private: static std::map sScriptNames; @@ -104,4 +106,18 @@ class LLRequireResolver bool findModuleImpl(const std::string& absolutePath); void runModule(const std::string& desc, const std::string& code); }; + +// RAII class to guarantee that a script entry is erased even when coro is terminated +class ScriptObserver +{ + public: + ScriptObserver(const std::string &coro_name, const std::string &filename) : mCoroName(coro_name) + { + LLLUAmanager::sScriptNames[mCoroName] = filename; + } + ~ScriptObserver() { LLLUAmanager::sScriptNames.erase(mCoroName); } + + private: + std::string mCoroName; +}; #endif -- cgit v1.2.3