mirror of
https://github.com/whoahq/whoa.git
synced 2026-03-05 15:42:17 +03:00
feat(ui): implement CSimpleFrame_GetScript
This commit is contained in:
parent
4857e817c5
commit
6a4a2110f4
@ -35,6 +35,33 @@ const char* FrameScript_Object::GetDisplayName() {
|
|||||||
return name ? name : "<unnamed>";
|
return name ? name : "<unnamed>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
FrameScript_Object::ScriptIx* FrameScript_Object::GetScriptByName(const char* name, FrameScript_Object::ScriptData& data) {
|
||||||
if (!SStrCmpI(name, "OnEvent", STORM_MAX_STR)) {
|
if (!SStrCmpI(name, "OnEvent", STORM_MAX_STR)) {
|
||||||
data.wrapper = "return function(self,event,...) %s end";
|
data.wrapper = "return function(self,event,...) %s end";
|
||||||
|
|||||||
@ -43,6 +43,7 @@ class FrameScript_Object {
|
|||||||
|
|
||||||
// Member functions
|
// Member functions
|
||||||
const char* GetDisplayName();
|
const char* GetDisplayName();
|
||||||
|
int32_t GetScript(lua_State* L);
|
||||||
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);
|
||||||
|
|||||||
@ -188,7 +188,10 @@ int32_t CSimpleFrame_HasScript(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t CSimpleFrame_GetScript(lua_State* L) {
|
int32_t CSimpleFrame_GetScript(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED(0);
|
auto type = CSimpleFrame::GetObjectType();
|
||||||
|
auto frame = static_cast<CSimpleFrame*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
|
||||||
|
return frame->GetScript(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CSimpleFrame_SetScript(lua_State* L) {
|
int32_t CSimpleFrame_SetScript(lua_State* L) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user