From 6a4a2110f4a709f5f11a1577e8f2229b60bcf37e Mon Sep 17 00:00:00 2001 From: fallenoak Date: Wed, 4 Feb 2026 11:37:30 -0600 Subject: [PATCH] feat(ui): implement CSimpleFrame_GetScript --- src/ui/FrameScript_Object.cpp | 27 +++++++++++++++++++++++++++ src/ui/FrameScript_Object.hpp | 1 + src/ui/simple/CSimpleFrameScript.cpp | 5 ++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/ui/FrameScript_Object.cpp b/src/ui/FrameScript_Object.cpp index 15b19a6..17ff3db 100644 --- a/src/ui/FrameScript_Object.cpp +++ b/src/ui/FrameScript_Object.cpp @@ -35,6 +35,33 @@ const char* FrameScript_Object::GetDisplayName() { return name ? name : ""; } +int32_t FrameScript_Object::GetScript(lua_State* L) { + if (!lua_isstring(L, 2)) { + luaL_error(L, "Usage: %s:GetScript(\"type\")", this->GetDisplayName()); + return 0; + } + + auto name = lua_tostring(L, 2); + ScriptData data; + + auto script = this->GetScriptByName(name, data); + + if (!script) { + luaL_error(L, "%s doesn't have a \"%s\" script", this->GetDisplayName(), lua_tostring(L, 2)); + return 0; + } + + // TODO taint management + + if (script->luaRef > 0) { + lua_rawgeti(L, LUA_REGISTRYINDEX, script->luaRef); + } else { + lua_pushnil(L); + } + + return 1; +} + FrameScript_Object::ScriptIx* FrameScript_Object::GetScriptByName(const char* name, FrameScript_Object::ScriptData& data) { if (!SStrCmpI(name, "OnEvent", STORM_MAX_STR)) { data.wrapper = "return function(self,event,...) %s end"; diff --git a/src/ui/FrameScript_Object.hpp b/src/ui/FrameScript_Object.hpp index e80049e..db4528f 100644 --- a/src/ui/FrameScript_Object.hpp +++ b/src/ui/FrameScript_Object.hpp @@ -43,6 +43,7 @@ class FrameScript_Object { // Member functions const char* GetDisplayName(); + int32_t GetScript(lua_State* L); int32_t RegisterScriptEvent(const char* name); void RegisterScriptObject(const char* name); void RunScript(ScriptIx const& script, int32_t argCount, const char* a4); diff --git a/src/ui/simple/CSimpleFrameScript.cpp b/src/ui/simple/CSimpleFrameScript.cpp index bfb22f4..45b2679 100644 --- a/src/ui/simple/CSimpleFrameScript.cpp +++ b/src/ui/simple/CSimpleFrameScript.cpp @@ -188,7 +188,10 @@ int32_t CSimpleFrame_HasScript(lua_State* L) { } int32_t CSimpleFrame_GetScript(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleFrame::GetObjectType(); + auto frame = static_cast(FrameScript_GetObjectThis(L, type)); + + return frame->GetScript(L); } int32_t CSimpleFrame_SetScript(lua_State* L) {