summaryrefslogtreecommitdiff
path: root/indra/newview/llluamanager.cpp
diff options
context:
space:
mode:
authorMnikolenko Productengine <mnikolenko@productengine.com>2023-09-06 14:09:00 +0300
committerMnikolenko Productengine <mnikolenko@productengine.com>2023-09-06 14:09:00 +0300
commitb51cef8c8eaafa873f2a62d967cc4fe62cc0d94e (patch)
tree73c563d2ca1125319de81f375b45693e651be0d6 /indra/newview/llluamanager.cpp
parentc8711f4ea5d941d12ae7e6cf99302bfc3211dd3c (diff)
addcallback to display error msg
Diffstat (limited to 'indra/newview/llluamanager.cpp')
-rw-r--r--indra/newview/llluamanager.cpp60
1 files changed, 43 insertions, 17 deletions
diff --git a/indra/newview/llluamanager.cpp b/indra/newview/llluamanager.cpp
index 516993c967..bb86731140 100644
--- a/indra/newview/llluamanager.cpp
+++ b/indra/newview/llluamanager.cpp
@@ -81,13 +81,27 @@ int lua_wear_by_name(lua_State *L)
return 1;
}
-bool checkLua(lua_State *L, int r)
+int lua_open_floater(lua_State *L)
+{
+ std::string floater_name(lua_tostring(L, 1));
+
+ LLSD key;
+ if (floater_name == "profile")
+ {
+ key["id"] = gAgentID;
+ }
+ LLFloaterReg::showInstance(floater_name, key);
+
+ return 1;
+}
+
+bool checkLua(lua_State *L, int r, std::string &error_msg)
{
if (r != LUA_OK)
{
- std::string lua_error = lua_tostring(L, -1);
+ error_msg = lua_tostring(L, -1);
- LL_WARNS() << lua_error << LL_ENDL;
+ LL_WARNS() << error_msg << LL_ENDL;
return false;
}
return true;
@@ -95,18 +109,19 @@ bool checkLua(lua_State *L, int r)
void initLUA(lua_State *L)
{
- lua_register(L, "lua_printWarning", lua_printWarning);
+ lua_register(L, "print_warning", lua_printWarning);
- lua_register(L, "lua_avatar_sit", lua_avatar_sit);
- lua_register(L, "lua_avatar_stand", lua_avatar_stand);
+ lua_register(L, "avatar_sit", lua_avatar_sit);
+ lua_register(L, "avatar_stand", lua_avatar_stand);
- lua_register(L, "lua_nearby_chat_send", lua_nearby_chat_send);
- lua_register(L, "lua_wear_by_name", lua_wear_by_name);
+ lua_register(L, "nearby_chat_send", lua_nearby_chat_send);
+ lua_register(L, "wear_by_name", lua_wear_by_name);
+ lua_register(L, "open_floater", lua_open_floater);
}
-void LLLUAmanager::runScriptFile(const std::string &filename)
+void LLLUAmanager::runScriptFile(const std::string &filename, script_finished_fn cb)
{
- LLCoros::instance().launch("LUAScriptFileCoro", [filename]()
+ LLCoros::instance().launch("LUAScriptFileCoro", [filename, cb]()
{
lua_State *L = luaL_newstate();
luaL_openlibs(L);
@@ -121,32 +136,43 @@ void LLLUAmanager::runScriptFile(const std::string &filename)
lua_register(L, "sleep", LUA_sleep_func);
- if (checkLua(L, luaL_dofile(L, filename.c_str())))
+ std::string lua_error;
+ if (checkLua(L, luaL_dofile(L, filename.c_str()), lua_error))
{
lua_getglobal(L, "call_once_func");
if (lua_isfunction(L, -1))
{
- if (checkLua(L, lua_pcall(L, 0, 0, 0))) {}
+ if (checkLua(L, lua_pcall(L, 0, 0, 0), lua_error)) {}
}
}
-
lua_close(L);
+
+ if (cb)
+ {
+ cb(lua_error);
+ }
});
}
-void LLLUAmanager::runScriptLine(const std::string &cmd)
+void LLLUAmanager::runScriptLine(const std::string &cmd, script_finished_fn cb)
{
- LLCoros::instance().launch("LUAScriptFileCoro", [cmd]()
+ LLCoros::instance().launch("LUAScriptFileCoro", [cmd, cb]()
{
lua_State *L = luaL_newstate();
luaL_openlibs(L);
initLUA(L);
int r = luaL_dostring(L, cmd.c_str());
+
+ std::string lua_error;
if (r != LUA_OK)
{
- std::string lua_error = lua_tostring(L, -1);
- LL_WARNS() << lua_error << LL_ENDL;
+ lua_error = lua_tostring(L, -1);
}
lua_close(L);
+
+ if (cb)
+ {
+ cb(lua_error);
+ }
});
}