summaryrefslogtreecommitdiff
path: root/indra/newview/llpreviewscript.cpp
diff options
context:
space:
mode:
authorAndrey Lihatskiy <alihatskiy@productengine.com>2025-03-14 07:20:07 +0200
committerAndrey Lihatskiy <alihatskiy@productengine.com>2025-03-14 13:25:21 +0200
commitda0a819d64514cad17cf306c3ebe2ac79db8283a (patch)
treef85fc4db056330c8cfb63d4e3045b77db182facd /indra/newview/llpreviewscript.cpp
parent5b23e28703dd6bb2dfee6fc9a446679467d4ab99 (diff)
Temporary hack to determine script language when opened from inventory
Diffstat (limited to 'indra/newview/llpreviewscript.cpp')
-rw-r--r--indra/newview/llpreviewscript.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp
index 5ab624a4c1..98c28ffadc 100644
--- a/indra/newview/llpreviewscript.cpp
+++ b/indra/newview/llpreviewscript.cpp
@@ -90,6 +90,7 @@
#include "lltoggleablemenu.h"
#include "llmenubutton.h"
#include "llinventoryfunctions.h"
+#include <regex>
const std::string HELP_LSL_PORTAL_TOPIC = "LSL_Portal";
@@ -129,6 +130,19 @@ static bool have_lua_enabled(const LLUUID& object_id)
return false;
}
+// TEMPORARY: Quick check to see if the code is Lua
+// since we don't have another way to determine the language yet
+static bool is_lua_script(const std::string& code)
+{
+ // Check for LSL's signature "default" state pattern
+ std::regex lsl_pattern("\\s*default\\s*\\{");
+ if (std::regex_search(code, lsl_pattern))
+ return false;
+
+ // "default" state not found, assuming it's Lua
+ return true;
+}
+
/// ---------------------------------------------------------------------------
/// LLLiveLSLFile
/// ---------------------------------------------------------------------------
@@ -1923,6 +1937,12 @@ void LLPreviewLSL::onLoadComplete(const LLUUID& asset_uuid, LLAssetType::EType t
preview->mScriptEd->setEnableEditing(is_modifiable);
preview->mScriptEd->setAssetID(asset_uuid);
preview->mAssetStatus = PREVIEW_ASSET_LOADED;
+
+ // Temporary hack to determine if the script is LSL or SLua when loaded from the inventory.
+ bool is_lua = is_lua_script(std::string(buffer.begin(), buffer.end()));
+ preview->mScriptEd->mEditor->setLuauLanguage(is_lua);
+ preview->mScriptEd->mCompileTarget->setValue(is_lua ? "luau" : "lsl-luau");
+ preview->mScriptEd->processKeywords(is_lua);
}
else
{