public void DestroyLua() { if (luaState == null) { 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, "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 */ return; } Lua.lua_pushnil(l); /* -2: LWF.Instances */ /* -1: nil */ Lua.lua_setfield(l, -2, instanceIdString); /* LWF.Instances.<instanceId> = nil */ /* -1: LWF.Instances */ Lua.lua_pop(l, 1); /* 0 */ Luna_LWF_LWF.Destroy(l, this); LuaLWF.close(l); }
public void InitLua() { m_eventFunctions = new EventFunctions(); if (luaState == null) { 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 */ LuaLWF.open(l); Lua.lua_getglobal(l, "LWF"); /* -1: LWF */ } Lua.lua_getfield(l, -1, "LWF"); /* -2: LWF */ /* -1: LWF.LWF */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 2); /* 0 */ LuaLWF.open(l); Lua.lua_getglobal(l, "LWF"); /* -1: LWF */ } else { Lua.lua_pop(l, 1); /* -1: LWF */ } Lua.lua_getfield(l, -1, "Instances"); /* -2: LWF */ /* -1: LWF.Instances */ if (!Lua.lua_istable(l, -1)) { Lua.lua_pop(l, 1); /* -1: LWF */ Lua.lua_newtable(l); /* -2: LWF */ /* -1: table */ Lua.lua_pushvalue(l, -1); /* -3: LWF */ /* -2: table */ /* -1: table */ Lua.lua_setfield(l, -3, "Instances"); /* -2: LWF */ /* -1: table (LWF.Instances) */ } Lua.lua_remove(l, -2); /* -1: LWF.Instances */ Lua.lua_newtable(l); /* -2: LWF.Instances */ /* -1: table */ Lua.lua_pushvalue(l, -1); /* -3: LWF.Instances */ /* -2: table */ /* -1: table */ Lua.lua_setfield(l, -3, instanceIdString); /* -2: LWF.Instances */ /* -1: LWF.Instances.<instanceId> */ Lua.lua_remove(l, -2); /* -1: LWF.Instances.<instanceId> */ Lua.lua_newtable(l); /* -2: LWF.Instances.<instanceId> */ /* -1: table */ Lua.lua_setfield(l, -2, "Handlers"); /* -1: LWF.Instances.<instanceId> */ Lua.lua_newtable(l); /* LWF.Instances.<instanceId>.Handlers = {} */ /* -2: LWF.Instances.<instanceId> */ /* -1: table */ Lua.lua_setfield(l, -2, "Movies"); /* LWF.Instances.<instanceId>.Movies = {} */ /* -1: LWF.Instances.<instanceId> */ Lua.lua_pop(l, 1); /* 0 */ Lua.lua_getglobal(l, "LWF"); /* -1: LWF */ 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_"; for (int eventId = 0; eventId < data.events.Length; ++eventId) { Lua.lua_getfield(l, -1, (ev + data.strings[data.events[eventId].stringId])); /* -2: LWF.Script.<name> */ /* -1: function or nil: LWF.Script.<name>.Event_<eventname> */ if (Lua.lua_isfunction(l, -1)) { m_eventFunctions[eventId] = true; } Lua.lua_pop(l, 1); /* -1: LWF.Script.<name> */ } Lua.lua_pop(l, 1); /* 0 */ }