summaryrefslogtreecommitdiff
path: root/indra/newview/llpreviewscript.cpp
diff options
context:
space:
mode:
authorAndrey Lihatskiy <alihatskiy@productengine.com>2025-03-14 16:08:42 +0200
committerGitHub <noreply@github.com>2025-03-14 16:08:42 +0200
commite2333b4d312301206f80f60e9c2f0258bc8e6235 (patch)
treef85fc4db056330c8cfb63d4e3045b77db182facd /indra/newview/llpreviewscript.cpp
parent7aad509d19c75277519dbcf119c3ba2e1f8a9c7c (diff)
parentda0a819d64514cad17cf306c3ebe2ac79db8283a (diff)
Merge pull request #3701 from secondlife/marchcat/lua_editor
Lua editor: WIP updates
Diffstat (limited to 'indra/newview/llpreviewscript.cpp')
-rw-r--r--indra/newview/llpreviewscript.cpp71
1 files changed, 26 insertions, 45 deletions
diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp
index 28988f9564..98c28ffadc 100644
--- a/indra/newview/llpreviewscript.cpp
+++ b/indra/newview/llpreviewscript.cpp
@@ -90,20 +90,8 @@
#include "lltoggleablemenu.h"
#include "llmenubutton.h"
#include "llinventoryfunctions.h"
+#include <regex>
-const std::string HELLO_LSL =
- "default\n"
- "{\n"
- " state_entry()\n"
- " {\n"
- " llSay(0, \"Hello, Avatar!\");\n"
- " }\n"
- "\n"
- " touch_start(integer total_number)\n"
- " {\n"
- " llSay(0, \"Touched.\");\n"
- " }\n"
- "}\n";
const std::string HELP_LSL_PORTAL_TOPIC = "LSL_Portal";
const std::string DEFAULT_SCRIPT_NAME = "New Script"; // *TODO:Translate?
@@ -142,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
/// ---------------------------------------------------------------------------
@@ -396,9 +397,9 @@ LLScriptEdCore::LLScriptEdCore(
LLScriptEdContainer* container,
const std::string& sample,
const LLHandle<LLFloater>& floater_handle,
- void (*load_callback)(void*),
- void (*save_callback)(void*, bool),
- void (*search_replace_callback) (void* userdata),
+ script_ed_callback_t load_callback,
+ save_callback_t save_callback,
+ script_ed_callback_t search_replace_callback,
void* userdata,
bool live,
S32 bottom_pad)
@@ -1617,7 +1618,7 @@ void* LLPreviewLSL::createScriptEdPanel(void* userdata)
self->mScriptEd = new LLScriptEdCore(
self,
- HELLO_LSL,
+ std::string(),
self->getHandle(),
LLPreviewLSL::onLoad,
LLPreviewLSL::onSave,
@@ -1758,12 +1759,6 @@ void LLPreviewLSL::loadAsset()
getChildView("lock")->setVisible( !is_modifiable);
mScriptEd->getChildView("Insert...")->setEnabled(is_modifiable);
}
- else
- {
- mScriptEd->setScriptText(std::string(HELLO_LSL), true);
- mScriptEd->setEnableEditing(true);
- mAssetStatus = PREVIEW_ASSET_LOADED;
- }
}
@@ -1942,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
{
@@ -1979,7 +1980,7 @@ void* LLLiveLSLEditor::createScriptEdPanel(void* userdata)
self->mScriptEd = new LLScriptEdCore(
self,
- HELLO_LSL,
+ std::string(),
self->getHandle(),
&LLLiveLSLEditor::onLoad,
&LLLiveLSLEditor::onSave,
@@ -2007,7 +2008,7 @@ LLLiveLSLEditor::LLLiveLSLEditor(const LLSD& key) :
bool LLLiveLSLEditor::postBuild()
{
- mResetButton = getChild<LLButton>("reset");
+ mResetButton = getChild<LLButton>("Reset");
mResetButton->setClickedCallback([&](LLUICtrl*, const LLSD&) { onReset(); });
mRunningCheckbox = getChild<LLCheckBoxCtrl>("running");
@@ -2153,26 +2154,6 @@ void LLLiveLSLEditor::loadAsset()
*/
}
}
- else
- {
- mScriptEd->setScriptText(std::string(HELLO_LSL), true);
- mScriptEd->enableSave(false);
- LLPermissions perm;
- perm.init(gAgent.getID(), gAgent.getID(), LLUUID::null, gAgent.getGroupID());
- perm.initMasks(PERM_ALL, PERM_ALL, PERM_NONE, PERM_NONE, PERM_MOVE | PERM_TRANSFER);
- mItem = new LLViewerInventoryItem(mItemUUID,
- mObjectUUID,
- perm,
- LLUUID::null,
- LLAssetType::AT_LSL_TEXT,
- LLInventoryType::IT_LSL,
- DEFAULT_SCRIPT_NAME,
- DEFAULT_SCRIPT_DESC,
- LLSaleInfo::DEFAULT,
- LLInventoryItemFlags::II_FLAGS_NONE,
- time_corrected());
- mAssetStatus = PREVIEW_ASSET_LOADED;
- }
requestExperiences();
}