mirror of
https://github.com/whoahq/whoa.git
synced 2026-02-02 00:32:45 +03:00
feat(ui): implement CSimpleFrame_SetScript
This commit is contained in:
parent
54b2cdb678
commit
034e9d0915
@ -129,7 +129,10 @@ int32_t CSimpleFrame_GetScript(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t CSimpleFrame_SetScript(lua_State* L) {
|
int32_t CSimpleFrame_SetScript(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED(0);
|
auto type = CSimpleFrame::GetObjectType();
|
||||||
|
auto frame = static_cast<CSimpleFrame*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
|
||||||
|
return frame->SetScript(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CSimpleFrame_HookScript(lua_State* L) {
|
int32_t CSimpleFrame_HookScript(lua_State* L) {
|
||||||
|
|||||||
@ -142,6 +142,30 @@ void FrameScript_Object::RunScript(ScriptIx const& script, int32_t argCount, con
|
|||||||
FrameScript_Execute(script.luaRef, this, argCount, a4 ? a4 : script.unk, nullptr);
|
FrameScript_Execute(script.luaRef, this, argCount, a4 ? a4 : script.unk, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t FrameScript_Object::SetScript(lua_State* L) {
|
||||||
|
if (!lua_isstring(L, 2) || lua_type(L, 3) != LUA_TFUNCTION && lua_type(L, 3)) {
|
||||||
|
return luaL_error(L, "Usage: %s:SetScript(\"type\", function)", this->GetDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptData data;
|
||||||
|
auto script = this->GetScriptByName(lua_tostring(L, 2), data);
|
||||||
|
|
||||||
|
if (!script) {
|
||||||
|
return luaL_error(L, "%s doesn't have a \"%s\" script", this->GetDisplayName(), lua_tostring(L, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (script->luaRef) {
|
||||||
|
luaL_unref(L, LUA_REGISTRYINDEX, script->luaRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto luaRef = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
|
script->luaRef = luaRef <= 0 ? 0 : luaRef;
|
||||||
|
|
||||||
|
// TODO taint tracking
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void FrameScript_Object::UnregisterScriptObject(const char* name) {
|
void FrameScript_Object::UnregisterScriptObject(const char* name) {
|
||||||
auto L = FrameScript_GetContext();
|
auto L = FrameScript_GetContext();
|
||||||
|
|
||||||
|
|||||||
@ -45,6 +45,7 @@ class FrameScript_Object {
|
|||||||
int32_t RegisterScriptEvent(const char* name);
|
int32_t RegisterScriptEvent(const char* name);
|
||||||
void RegisterScriptObject(const char* name);
|
void RegisterScriptObject(const char* name);
|
||||||
void RunScript(ScriptIx const& script, int32_t argCount, const char* a4);
|
void RunScript(ScriptIx const& script, int32_t argCount, const char* a4);
|
||||||
|
int32_t SetScript(lua_State* L);
|
||||||
void UnregisterScriptObject(const char* name);
|
void UnregisterScriptObject(const char* name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user