diff --git a/src/ui/simple/CSimpleFrame.cpp b/src/ui/simple/CSimpleFrame.cpp index 6f95f38..0e03001 100644 --- a/src/ui/simple/CSimpleFrame.cpp +++ b/src/ui/simple/CSimpleFrame.cpp @@ -95,6 +95,10 @@ void CSimpleFrame::AddFrameRegion(CSimpleRegion* region, uint32_t drawlayer) { this->NotifyDrawLayerChanged(drawlayer); } +int32_t CSimpleFrame::AttributeChangesAllowed() { + return true; +} + void CSimpleFrame::DisableDrawLayer(uint32_t drawlayer) { this->m_drawenabled[drawlayer] = 0; this->NotifyDrawLayerChanged(drawlayer); diff --git a/src/ui/simple/CSimpleFrame.hpp b/src/ui/simple/CSimpleFrame.hpp index 21ce7ea..f0641da 100644 --- a/src/ui/simple/CSimpleFrame.hpp +++ b/src/ui/simple/CSimpleFrame.hpp @@ -128,6 +128,7 @@ class CSimpleFrame : public CScriptRegion { // Member functions CSimpleFrame(CSimpleFrame* parent); void AddFrameRegion(CSimpleRegion* region, uint32_t drawlayer); + int32_t AttributeChangesAllowed(); void DisableDrawLayer(uint32_t drawlayer); void DisableEvent(CSimpleEventType eventType); void EnableDrawLayer(uint32_t drawlayer); diff --git a/src/ui/simple/CSimpleFrameScript.cpp b/src/ui/simple/CSimpleFrameScript.cpp index cd2f78f..118c11b 100644 --- a/src/ui/simple/CSimpleFrameScript.cpp +++ b/src/ui/simple/CSimpleFrameScript.cpp @@ -209,7 +209,38 @@ int32_t CSimpleFrame_GetAttribute(lua_State* L) { } int32_t CSimpleFrame_SetAttribute(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleFrame::GetObjectType(); + auto frame = static_cast(FrameScript_GetObjectThis(L, type)); + + if (!frame->ProtectedFunctionsAllowed() && !frame->AttributeChangesAllowed()) { + // TODO disallowed logic + + return 0; + } + + lua_settop(L, 3); + + if (!lua_isstring(L, 2) || lua_type(L, 3) == LUA_TNONE) { + luaL_error(L, "Usage: %s:SetAttribute(\"name\", value)", frame->GetDisplayName()); + return 0; + } + + auto attrName = lua_tostring(L, 2); + int32_t luaRef; + + if (frame->GetAttribute(attrName, luaRef)) { + luaL_unref(L, LUA_REGISTRYINDEX, luaRef); + } + + // TODO taint management + + luaRef = luaL_ref(L, LUA_REGISTRYINDEX); + + // TODO taint management + + frame->SetAttribute(attrName, luaRef); + + return 0; } int32_t CSimpleFrame_GetEffectiveScale(lua_State* L) {