diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2024-02-09 09:19:27 -0500 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2024-02-09 09:19:27 -0500 |
commit | 8e3375534607a1a6648ace18f7293a2c0a096862 (patch) | |
tree | d4c9d553491fca339759a262d6d5a4f18380059f | |
parent | 72e680cfae03aa86659b6c2165e16ce46487097b (diff) |
When LLFloaterLUADebug script returns a value, display the value.
The chunk:
return 1, 2, {}
differs in two ways from:
print(1, 2, {})
First, print() engages the Lua tostring() builtin, so it displays values as
Lua sees them. (For a table, tostring() displays "table: hex", which isn't so
wonderful.) But LLFloaterLUADebug serializes the LLSD converted from the Lua
return values.
Second, we've overridden print() to engage a function that writes to the
viewer log as well as displaying to LLFloaterLUADebug. (As we go forward, most
Lua scripts won't be run manually by LLFloaterLUADebug.) The values returned
by a Lua chunk aren't implicitly logged. Each C++ caller wanting to evaluate a
Lua expression can choose whether to log the results.
-rw-r--r-- | indra/newview/llfloaterluadebug.cpp | 41 | ||||
-rw-r--r-- | indra/newview/llfloaterluadebug.h | 2 |
2 files changed, 36 insertions, 7 deletions
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; |