Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions indra/newview/llpanelcontents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@ void LLPanelContents::clearContents()
// Static functions
//

// See below comment in `onClickNewScript()` about this hack :(
static const std::string DEFAULT_SLUA_SCRIPT = R"(
function LLEvents.touch_start(detected)
ll.Say(0, "Touched.")
end

local function main()
print("Hello, Avatar!")
end

main()
)";

// static
void LLPanelContents::onClickNewScript(void *userdata)
{
Expand Down Expand Up @@ -274,18 +287,6 @@ void LLPanelContents::onClickNewScript(void *userdata)
LLViewerInventoryItem* item = gInventory.getItem(inv_item);
if (item)
{
const std::string hello_lua_script =
"function state_entry()\n"
" ll.Say(0, \"Hello, Avatar!\")\n"
"end\n"
"\n"
"function touch_start(total_number)\n"
" ll.Say(0, \"Touched.\")\n"
"end\n"
"\n"
"-- Simulate the state_entry event\n"
"state_entry()\n";

auto scriptUploadFinished = [object, item](LLUUID itemId, LLUUID newAssetId, LLUUID newItemId, LLSD response)
{
LLPointer<LLViewerInventoryItem> new_script = new LLViewerInventoryItem(item);
Expand All @@ -312,7 +313,7 @@ void LLPanelContents::onClickNewScript(void *userdata)
LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared<LLScriptAssetUpload>(
item->getUUID(),
"luau",
hello_lua_script,
DEFAULT_SLUA_SCRIPT,
scriptUploadFinished,
nullptr));

Expand Down
28 changes: 14 additions & 14 deletions indra/newview/llviewerinventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,19 @@ void set_default_permissions(LLViewerInventoryItem* item, std::string perm_type)
}
}

// See below comment in `create_script_cb()` about this hack :(
static const std::string DEFAULT_SLUA_SCRIPT = R"(
function LLEvents.touch_start(detected)
ll.Say(0, "Touched.")
end

local function main()
print("Hello, Avatar!")
end

main()
)";

void create_script_cb(const LLUUID& inv_item)
{
if (!inv_item.isNull())
Expand All @@ -1039,26 +1052,13 @@ void create_script_cb(const LLUUID& inv_item)
region->getSimulatorFeatures(simulatorFeatures);
if (simulatorFeatures["LuaScriptsEnabled"].asBoolean())
{

const std::string hello_lua_script =
"function state_entry()\n"
" ll.Say(0, \"Hello, Avatar!\")\n"
"end\n"
"\n"
"function touch_start(total_number)\n"
" ll.Say(0, \"Touched.\")\n"
"end\n"
"\n"
"-- Simulate the state_entry event\n"
"state_entry()\n";

std::string url = gAgent.getRegion()->getCapability("UpdateScriptAgent");
if (!url.empty())
{
LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared<LLScriptAssetUpload>(
item->getUUID(),
"luau",
hello_lua_script,
DEFAULT_SLUA_SCRIPT,
nullptr,
nullptr));

Expand Down