summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/llfloaterluascripts.cpp16
-rw-r--r--indra/newview/llfloaterluascripts.h1
-rw-r--r--indra/newview/llluamanager.cpp15
-rw-r--r--indra/newview/llluamanager.h5
-rw-r--r--indra/newview/skins/default/xui/en/menu_lua_scripts.xml8
5 files changed, 41 insertions, 4 deletions
diff --git a/indra/newview/llfloaterluascripts.cpp b/indra/newview/llfloaterluascripts.cpp
index bd845a97d6..30353a7210 100644
--- a/indra/newview/llfloaterluascripts.cpp
+++ b/indra/newview/llfloaterluascripts.cpp
@@ -43,7 +43,20 @@ LLFloaterLUAScripts::LLFloaterLUAScripts(const LLSD &key)
{
mCommitCallbackRegistrar.add("Script.OpenFolder", [this](LLUICtrl*, const LLSD &userdata)
{
- gViewerWindow->getWindow()->openFolder(mTargetFolderPath);
+ if (mScriptList->hasSelectedItem())
+ {
+ std::string target_folder_path = std::filesystem::path((mScriptList->getFirstSelected()->getColumn(1)->getValue().asString())).parent_path().string();
+ gViewerWindow->getWindow()->openFolder(target_folder_path);
+ }
+ });
+ mCommitCallbackRegistrar.add("Script.Terminate", [this](LLUICtrl*, const LLSD &userdata)
+ {
+ if (mScriptList->hasSelectedItem())
+ {
+ std::string coro_name = mScriptList->getSelectedValue();
+ LLEventPumps::instance().obtain("LLLua").post(llsd::map("status", "close", "coro", coro_name));
+ LLLUAmanager::terminateScript(coro_name);
+ }
});
}
@@ -112,7 +125,6 @@ void LLFloaterLUAScripts::onScrollListRightClicked(LLUICtrl *ctrl, S32 x, S32 y)
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
index 548bbd10f6..932c5c78dd 100644
--- a/indra/newview/llfloaterluascripts.h
+++ b/indra/newview/llfloaterluascripts.h
@@ -46,7 +46,6 @@ private:
std::unique_ptr<LLTimer> mUpdateTimer;
LLScrollListCtrl* mScriptList;
- std::string mTargetFolderPath;
LLHandle<LLContextMenu> mContextMenuHandle;
};
diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp
index 1d55313813..853ed5a634 100644
--- a/indra/newview/llluamanager.cpp
+++ b/indra/newview/llluamanager.cpp
@@ -49,6 +49,7 @@
#include <vector>
std::map<std::string, std::string> LLLUAmanager::sScriptNames;
+std::set<std::string> LLLUAmanager::sTerminationList;
lua_function(sleep, "sleep(seconds): pause the running coroutine")
{
@@ -188,6 +189,20 @@ void LLLUAmanager::runScriptFile(const std::string &filename, script_result_fn r
// A script_finished_fn is used to initialize the LuaState.
// It will be called when the LuaState is destroyed.
LuaState L(finished_cb);
+
+ lua_callbacks(L)->interrupt = [](lua_State *L, int gc)
+ {
+ // skip if we're interrupting only for garbage collection
+ if (gc >= 0)
+ return;
+
+ auto it = sTerminationList.find(LLCoros::getName());
+ if (it != sTerminationList.end())
+ {
+ sTerminationList.erase(it);
+ lluau::error(L, "Script was terminated");
+ }
+ };
std::string text{std::istreambuf_iterator<char>(in_file), {}};
auto [count, result] = L.expr(filename, text);
if (result_cb)
diff --git a/indra/newview/llluamanager.h b/indra/newview/llluamanager.h
index fe4db22fca..d671719bc4 100644
--- a/indra/newview/llluamanager.h
+++ b/indra/newview/llluamanager.h
@@ -85,9 +85,12 @@ public:
static void runScriptOnLogin();
static const std::map<std::string, std::string> getScriptNames() { return sScriptNames; }
+ static std::set<std::string> getTerminationList() { return sTerminationList; }
+ static void terminateScript(std::string& coro_name) { sTerminationList.insert(coro_name); }
private:
- static std::map<std::string, std::string> sScriptNames;
+ static std::map<std::string, std::string> sScriptNames;
+ static std::set<std::string> sTerminationList;
};
class LLRequireResolver
diff --git a/indra/newview/skins/default/xui/en/menu_lua_scripts.xml b/indra/newview/skins/default/xui/en/menu_lua_scripts.xml
index 8f718abe17..645fee405d 100644
--- a/indra/newview/skins/default/xui/en/menu_lua_scripts.xml
+++ b/indra/newview/skins/default/xui/en/menu_lua_scripts.xml
@@ -8,4 +8,12 @@
<menu_item_call.on_click
function="Script.OpenFolder" />
</menu_item_call>
+ <menu_item_separator/>
+ <menu_item_call
+ label="Terminate script"
+ layout="topleft"
+ name="terminate">
+ <menu_item_call.on_click
+ function="Script.Terminate" />
+ </menu_item_call>
</context_menu>