public static void open(Lua.lua_State L) { Luna.dostring(L, "if __luna==nil then __luna={} end"); Luna.dostring(L, " if __luna.copyMethodsFrom==nil then\n function __luna.copyMethodsFrom(methodsChild, methodsParent)\n for k,v in pairs(methodsParent) do\n if k~='__index' and k~='__newindex' and methodsChild[k]==nil then\n methodsChild[k]=v\n end\n end\n end\n function __luna.overwriteMethodsFrom(methodsChild, methodsParent)\n for k,v in pairs(methodsParent) do\n if k~='__index' and k~='__newindex' then\n if verbose then print('registering', k, methodsChild[k]) end\n methodsChild[k]=v\n end\n end\n end\n end\n "); impl_LunaTraits_LWF_LWF.luna_init_hashmap(); impl_LunaTraits_LWF_LWF.luna_init_write_hashmap(); Luna_LWF_LWF.Register(L); Luna.dostring(L, "if not LWF then LWF={} end LWF.LWF=__luna.LWF_LWF"); Luna.dostring(L, " __luna.LWF_LWF.luna_class='.LWF'"); impl_LunaTraits_LWF_Button.luna_init_hashmap(); impl_LunaTraits_LWF_Button.luna_init_write_hashmap(); Luna_LWF_Button.Register(L); Luna.dostring(L, "if not LWF then LWF={} end LWF.Button=__luna.LWF_Button"); Luna.dostring(L, " __luna.LWF_Button.luna_class='.Button'"); impl_LunaTraits_LWF_Movie.luna_init_hashmap(); impl_LunaTraits_LWF_Movie.luna_init_write_hashmap(); Luna_LWF_Movie.Register(L); Luna.dostring(L, "if not LWF then LWF={} end LWF.Movie=__luna.LWF_Movie"); Luna.dostring(L, " __luna.LWF_Movie.luna_class='.Movie'"); impl_LunaTraits_LWF_Point.luna_init_hashmap(); impl_LunaTraits_LWF_Point.luna_init_write_hashmap(); Luna_LWF_Point.Register(L); Luna.dostring(L, "if not LWF then LWF={} end LWF.Point=__luna.LWF_Point"); Luna.dostring(L, " __luna.LWF_Point.luna_class='.Point'"); }
public static void close(Lua.lua_State L) { Luna_LWF_LWF.Unregister(L); Luna_LWF_Button.Unregister(L); Luna_LWF_Movie.Unregister(L); Luna_LWF_Point.Unregister(L); }
public static int _bind_getParent(Lua.lua_State L) { if (Lua.lua_gettop(L) != 1 || Luna.get_uniqueid(L, 1) != LunaTraits_LWF_Button.uniqueID) { Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed: LWF.Button.parent"); } LWF.Button a = Luna_LWF_Button.check(L, 1); Luna_LWF_Movie.push(L, a.parent, false); return(1); }
public static int addEventListener(Lua.lua_State L) { if (Lua.lua_gettop(L) != 3 || Luna.get_uniqueid(L, 1) != LunaTraits_LWF_Button.uniqueID || Lua.lua_isstring(L, 2) == 0 || !Lua.lua_isfunction(L, 3)) { Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed: LWF.Button.addEventListener"); } LWF.Button a = Luna_LWF_Button.check(L, 1); return(a.lwf.AddEventHandlerLua(null, a)); }
public static int _bind_getHeight(Lua.lua_State L) { if (Lua.lua_gettop(L) != 1 || Luna.get_uniqueid(L, 1) != 8952431) { Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:getHeight(LWF.Button self ...)"); } LWF.Button o = Luna_LWF_Button.check(L, 1); try { float ret = getHeight(o); Lua.lua_pushnumber(L, ret); } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); } return(1); }
public static int _bind_getFullName(Lua.lua_State L) { if (Lua.lua_gettop(L) != 1 || Luna.get_uniqueid(L, 1) != 8952431) { Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:getFullName(LWF.Button self)"); } LWF.Button self = Luna_LWF_Button.check(L, 1); try { string ret = self.GetFullName(); Lua.lua_pushstring(L, ret); } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); } return(1); }
public static int __index(Lua.lua_State L) { if (Lua.lua_gettop(L) == 2 && Luna.get_uniqueid(L, 1) == LunaTraits_LWF_Movie.uniqueID) { LWF.Movie o = Luna_LWF_Movie.check(L, 1); string name = Lua.lua_tostring(L, 2).ToString(); if (o.lwf.GetFieldLua(o, name)) { return(1); } LWF.Movie movie = o.SearchMovieInstance(name, false); if (movie != null) { Lua.lua_pop(L, 1); Luna_LWF_Movie.push(L, movie, false); return(1); } LWF.Button button = o.SearchButtonInstance(name, false); if (button != null) { Lua.lua_pop(L, 1); Luna_LWF_Button.push(L, button, false); return(1); } } { Lua.lua_CFunction fnc = null; if (LunaTraits_LWF_Movie.properties.TryGetValue(Lua.lua_tostring(L, 2).ToString(), out fnc)) { Lua.lua_pop(L, 1); // remove self return(fnc(L)); } } int mt = Lua.lua_getmetatable(L, 1); if (mt == 0) { Lua.luaL_error(L, "__index"); //end } Lua.lua_pushstring(L, Lua.lua_tostring(L, 2)); Lua.lua_rawget(L, -2); return(1); }
public static int _bind_clearEventListener(Lua.lua_State L) { if (Lua.lua_gettop(L) != 2 || Luna.get_uniqueid(L, 1) != 8952431 || Lua.lua_isstring(L, 2) == 0) { Luna.printStack(L); Lua.luaL_error(L, "luna typecheck failed:clearEventListener(LWF.Button self)"); } LWF.Button self = Luna_LWF_Button.check(L, 1); string eventName = Lua.lua_tostring(L, 2).ToString(); try { self.ClearEventHandler(eventName); } catch (Exception e) { Lua.luaL_error(L, new Lua.CharPtr(e.ToString())); } return(0); }
public int AddButtonEventHandlerLua() { if (luaState == null) { return(0); } Lua.lua_State l = (Lua.lua_State)luaState; string instanceName; ButtonEventHandlerDictionary handlers = new ButtonEventHandlerDictionary() { { "load", null }, { "unload", null }, { "enterFrame", null }, { "update", null }, { "render", null }, { "press", null }, { "release", null }, { "rollOver", null }, { "rollOut", null }, { "keyPress", null } }; int handlerId; /* 1: LWF_LWF instance */ /* 2: instanceName:string */ /* 3: table {key:string, handler:function} */ instanceName = Lua.lua_tostring(l, 2).ToString(); Lua.lua_getglobal(l, "LWF"); /* -1: LWF */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, "Instances"); /* -2: LWF */ /* -1: LWF.Instances */ Lua.lua_remove(l, -2); /* -1: LWF.Instances */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, instanceIdString); /* -2: LWF.Instances */ /* -1: LWF.Instances.<instanceId> */ Lua.lua_remove(l, -2); /* -1: LWF.Instances.<instanceId> */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, "Handlers"); /* -2: LWF.Instances.<instanceId> */ /* -1: LWF.Instances.<instanceId>.Handlers */ Lua.lua_remove(l, -2); /* -1: LWF.Instances.<instanceId>.Handlers */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_pushnil(l); /* -2: LWF.Instances.<instanceId>.Handlers */ /* -1: nil */ while (Lua.lua_next(l, 3) != 0) { /* -3: LWF.Instances.<instanceId>.Handlers */ /* -2: key: eventName string */ /* -1: value: handler function */ string key = Lua.lua_tostring(l, -2).ToString(); if (key != null && Lua.lua_isfunction(l, -1)) { int luaHandlerId = GetEventOffset(); handlers[key] = (Button a) => { if (!a.lwf.PushHandlerLua(luaHandlerId)) { return; } /* -1: function */ Lua.lua_State ls = (Lua.lua_State)a.lwf.luaState; Luna_LWF_Button.push(ls, a, false); /* -2: function */ /* -1: Movie or Button */ if (Lua.lua_pcall(ls, 1, 0, 0) != 0) { Lua.lua_pop(ls, 1); } /* 0 */ }; Lua.lua_setfield(l, -3, luaHandlerId.ToString()); /* LWF.Instances.<instanceId>.Handlers.<luaHandlerId> = function */ /* -2: LWF.Instances.<instanceId>.Handlers */ /* -1: key */ } else { Lua.lua_pop(l, 2); /* 0 */ goto error; } } /* -1: LWF.Instances.<instanceId>.Handlers */ Lua.lua_pop(l, 1); /* 0 */ handlerId = AddButtonEventHandler(instanceName, handlers["load"], handlers["unload"], handlers["enterFrame"], handlers["update"], handlers["render"], handlers["press"], handlers["release"], handlers["rollOver"], handlers["rollOut"]); Lua.lua_pushnumber(l, handlerId); /* handlerId */ return(1); error: Lua.lua_pushnumber(l, -1); /* -1: -1 */ return(1); }
public int AddEventHandlerLua(Movie movie = null, Button button = null) { if (luaState == null) { return(0); } Lua.lua_State l = (Lua.lua_State)luaState; string ev; int luaHandlerId; int handlerId; /* 1: LWF_LWF instance */ /* 2: string */ /* 3: function */ ev = Lua.lua_tostring(l, 2).ToString(); Lua.lua_getglobal(l, "LWF"); /* -1: LWF */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, "Instances"); /* -2: LWF */ /* -1: LWF.Instances */ Lua.lua_remove(l, -2); /* -1: LWF.Instances */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, instanceIdString); /* -2: LWF.Instances */ /* -1: LWF.Instances.<instanceId> */ Lua.lua_remove(l, -2); /* -1: LWF.Instances.<instanceId> */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, "Handlers"); /* -2: LWF.Instances.<instanceId> */ /* -1: LWF.Instances.<instanceId>.Handlers */ Lua.lua_remove(l, -2); /* -1: LWF.Instances.<instanceId>.Handlers */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_pushvalue(l, 3); /* -2: LWF.Instances.<instanceId>.Handlers */ /* -1: function */ luaHandlerId = GetEventOffset(); Lua.lua_setfield(l, -2, luaHandlerId.ToString()); /* LWF.Instances.<instanceId>.Handlers.<luaHandlerId> = function */ /* -1: LWF.Instances.<instanceId>.Handlers */ Lua.lua_pop(l, 1); /* 0 */ if (movie != null) { if (string.IsNullOrEmpty(ev) || MovieEvents.ContainsKey(ev)) { /* Movie event */ handlerId = movie.AddEventHandler(ev, (Movie m) => { Lua.lua_State _l = (Lua.lua_State)m.lwf.luaState; if (!m.lwf.PushHandlerLua(luaHandlerId)) { return; } /* -1: function */ Luna_LWF_Movie.push(_l, m, false); /* -2: function */ /* -1: Movie */ if (Lua.lua_pcall(_l, 1, 0, 0) != 0) { Lua.lua_pop(_l, 1); } }); } else { handlerId = movie.AddEventHandler(ev, () => { Lua.lua_State _l = (Lua.lua_State)movie.lwf.luaState; if (!movie.lwf.PushHandlerLua(luaHandlerId)) { return; } /* -1: function */ /* User defined event */ Lua.lua_createtable(_l, 0, 2); /* -2: function */ /* -1: table */ Lua.lua_pushstring(_l, ev); /* -3: function */ /* -2: table */ /* -1: string(type) */ Lua.lua_setfield(_l, -2, "type"); /* -2: function */ /* -1: table */ if (Lua.lua_istable(_l, 2)) { Lua.lua_getfield(_l, 2, "param"); /* -3: function */ /* -2: table */ /* -1: param */ } else { Lua.lua_pushnil(_l); /* -3: function */ /* -2: table */ /* -1: nil */ } Lua.lua_setfield(_l, -2, "param"); /* -2: function */ /* -1: table */ if (Lua.lua_pcall(_l, 1, 0, 0) != 0) { Lua.lua_pop(_l, 1); } /* 0 */ }); } } else if (button != null) { if (string.Compare(ev, "keyPress") == 0) { handlerId = button.AddEventHandler(ev, (Button b, int k) => { if (!b.lwf.PushHandlerLua(luaHandlerId)) { return; } /* -1: function */ Lua.lua_State _l = (Lua.lua_State)b.lwf.luaState; Luna_LWF_Button.push(_l, b, false); Lua.lua_pushnumber(_l, k); /* -3: function */ /* -2: Button */ /* -1: int */ if (Lua.lua_pcall(l, 2, 0, 0) != 0) { Lua.lua_pop(l, 1); } /* 0 */ }); } else { handlerId = button.AddEventHandler(ev, (Button b) => { if (!b.lwf.PushHandlerLua(luaHandlerId)) { return; } /* -1: function */ Lua.lua_State _l = (Lua.lua_State)b.lwf.luaState; Luna_LWF_Button.push(_l, b, false); /* -2: function */ /* -1: Button */ if (Lua.lua_pcall(l, 1, 0, 0) != 0) { Lua.lua_pop(l, 1); } /* 0 */ }); } } else { handlerId = AddEventHandler(ev, (Movie m, Button b) => { if (!m.lwf.PushHandlerLua(luaHandlerId)) { return; } /* -1: function */ Lua.lua_State _l = (Lua.lua_State)m.lwf.luaState; Luna_LWF_Movie.push(_l, m, false); Luna_LWF_Button.push(_l, b, false); /* -3: function */ /* -2: Movie */ /* -1: Button */ if (Lua.lua_pcall(l, 2, 0, 0) != 0) { Lua.lua_pop(l, 1); } /* 0 */ }); } Lua.lua_pushnumber(l, handlerId); /* -1: handlerId */ return(1); error: Lua.lua_pushnumber(l, -1); /* -1: -1 */ return(1); }
public void CallEventFunctionLua(int eventId, Movie movie, Button button) { if (luaState == null) { return; } if (!m_eventFunctions.ContainsKey(eventId)) { return; } Lua.lua_State l = (Lua.lua_State)luaState; Lua.lua_getglobal(l, "LWF"); /* -1: LWF */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ return; } Lua.lua_getfield(l, -1, "Script"); /* -2: LWF */ /* -1: LWF.Script */ Lua.lua_remove(l, -2); /* -1: LWF.Script */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ return; } Lua.lua_getfield(l, -1, name); /* -2: LWF.Script */ /* -1: LWF.Script.<name> */ Lua.lua_remove(l, -2); /* -1: LWF.Script.<name> */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ return; } string ev = "Event_"; Lua.lua_getfield(l, -1, (ev + data.strings[data.events[eventId].stringId])); /* -2: LWF.Script.<name> */ /* -1: LWF.Script.<name>.Event_<eventName> */ Lua.lua_remove(l, -2); /* -1: LWF.Script.<name>.Event_<eventName>*/ if (!Lua.lua_isfunction(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ return; } Luna_LWF_Movie.push(l, movie, false); /* -2: LWF.Script.<name>.Event_<eventName> */ /* -1: LWF_Movie instance */ Luna_LWF_Button.push(l, button, false); /* -3: LWF.Script.<name>.Event_<eventName> */ /* -2: LWF_Movie instance */ /* -1: LWF_Button instance */ if (Lua.lua_pcall(l, 2, 0, 0) != 0) { Lua.lua_pop(l, 1); } /* 0 */ }
public int AddEventHandlerLua() { if (luaState == null) { return(0); } Lua.lua_State l = (Lua.lua_State)luaState; string ev; int luaHandlerId; int handlerId; /* 1: LWF_LWF instance */ /* 2: string */ /* 3: function */ ev = Lua.lua_tostring(l, 2).ToString(); Lua.lua_getglobal(l, "LWF"); /* -1: LWF */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, "Instances"); /* -2: LWF */ /* -1: LWF.Instances */ Lua.lua_remove(l, -2); /* -1: LWF.Instances */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, instanceIdString); /* -2: LWF.Instances */ /* -1: LWF.Instances.<instanceId> */ Lua.lua_remove(l, -2); /* -1: LWF.Instances.<instanceId> */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_getfield(l, -1, "Handlers"); /* -2: LWF.Instances.<instanceId> */ /* -1: LWF.Instances.<instanceId>.Handlers */ Lua.lua_remove(l, -2); /* -1: LWF.Instances.<instanceId>.Handlers */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* 0 */ goto error; } Lua.lua_pushvalue(l, 3); /* -2: LWF.Instances.<instanceId>.Handlers */ /* -1: function */ luaHandlerId = GetEventOffset(); Lua.lua_setfield(l, -2, luaHandlerId.ToString()); /* LWF.Instances.<instanceId>.Handlers.<luaHandlerId> = function */ /* -1: LWF.Instances.<instanceId>.Handlers */ Lua.lua_pop(l, 1); /* 0 */ handlerId = AddEventHandler(ev, (Movie m, Button b) => { if (!m.lwf.PushHandlerLua(luaHandlerId)) { return; } /* -1: function */ Lua.lua_State _l = (Lua.lua_State)m.lwf.luaState; Luna_LWF_Movie.push(_l, m, false); Luna_LWF_Button.push(_l, b, false); /* -3: function */ /* -2: Movie */ /* -1: Button */ if (Lua.lua_pcall(l, 2, 0, 0) != 0) { Lua.lua_pop(l, 1); } /* 0 */ }); Lua.lua_pushnumber(l, handlerId); /* -1: handlerId */ return(1); error: Lua.lua_pushnumber(l, -1); /* -1: -1 */ return(1); }