diff options
author | nat-goodspeed <nat@lindenlab.com> | 2024-02-09 11:36:35 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-09 11:36:35 -0500 |
commit | 629aff3a53d887fcc83c39ce5f757e0142d6090a (patch) | |
tree | 554c1790e736dfa06a915ad5496cb0bf10c00903 | |
parent | 8cbeb93e9eb8e6ff2b33f63cf95648fbc6dfe273 (diff) | |
parent | 0fb18c30e6df203cd6de80eaeedd5ee3410d0d3a (diff) |
Merge pull request #22 from secondlife/implicit-print
When an LLFloaterLUADebug script returns a value, display the value.
-rw-r--r-- | indra/llcommon/lua_function.h | 2 | ||||
-rw-r--r-- | indra/newview/llfloaterluadebug.cpp | 41 | ||||
-rw-r--r-- | indra/newview/llfloaterluadebug.h | 2 |
3 files changed, 37 insertions, 8 deletions
diff --git a/indra/llcommon/lua_function.h b/indra/llcommon/lua_function.h index 26c399cdd1..c23bf533ba 100644 --- a/indra/llcommon/lua_function.h +++ b/indra/llcommon/lua_function.h @@ -151,7 +151,7 @@ static struct name##_luasub : public LuaFunction \ { \ name##_luasub(): LuaFunction(#name, &call, helptext) {} \ static int call(lua_State* L); \ -} name##_luadecl; \ +} name##_lua; \ int name##_luasub::call(lua_State* L) // { // ... supply method body here, referencing 'L' ... diff --git a/indra/newview/llfloaterluadebug.cpp b/indra/newview/llfloaterluadebug.cpp index 58639490db..b2c001817f 100644 --- a/indra/newview/llfloaterluadebug.cpp +++ b/indra/newview/llfloaterluadebug.cpp @@ -37,6 +37,9 @@ #include "llfloaterimnearbychat.h" #include "llluamanager.h" +#include "llsdutil.h" +#include "lua_function.h" +#include "stringize.h" LLFloaterLUADebug::LLFloaterLUADebug(const LLSD &key) @@ -74,9 +77,9 @@ void LLFloaterLUADebug::onExecuteClicked() mResultOutput->setValue(""); std::string cmd = mLineInput->getText(); - LLLUAmanager::runScriptLine(cmd, [this](std::string msg) - { - mResultOutput->insertText(msg); + LLLUAmanager::runScriptLine(cmd, [this](int count, const LLSD& result) + { + completion(count, result); }); } @@ -104,10 +107,34 @@ void LLFloaterLUADebug::runSelectedScript(const std::vector<std::string> &filena if (!filepath.empty()) { mScriptPath->setText(filepath); - LLLUAmanager::runScriptFile(filepath, [this](std::string msg) - { - mResultOutput->insertText(msg); - }); + LLLUAmanager::runScriptFile(filepath, [this](int count, const LLSD& result) + { + completion(count, result); + }); } } +void LLFloaterLUADebug::completion(int count, const LLSD& result) +{ + if (count < 0) + { + // error: show error message + mResultOutput->insertText("*** "); + mResultOutput->insertText(result.asString()); + return; + } + if (count == 1) + { + // single result + mResultOutput->insertText(stringize(result)); + return; + } + // 0 or multiple results + const char* sep = ""; + for (const auto& item : llsd::inArray(result)) + { + mResultOutput->insertText(sep); + mResultOutput->insertText(stringize(item)); + sep = ", "; + } +} diff --git a/indra/newview/llfloaterluadebug.h b/indra/newview/llfloaterluadebug.h index 1e26828c83..2dc59c5894 100644 --- a/indra/newview/llfloaterluadebug.h +++ b/indra/newview/llfloaterluadebug.h @@ -56,6 +56,8 @@ class LLFloaterLUADebug : void runSelectedScript(const std::vector<std::string> &filenames); private: + void completion(int count, const LLSD& result); + LLTempBoundListener mOutConnection; LLTextEditor* mResultOutput; |