private LuaTable GetLuaTable() { LuaTable luaModule = ezLua.luaRequire(moduleName); LuaAwake awake = luaModule.Get <LuaAwake>("LuaAwake"); LuaTable table = awake == null ? luaModule : awake.Invoke(this); luaStart = table.Get <LuaAction <LuaTable> >("LuaStart"); luaOnEnable = table.Get <LuaAction <LuaTable> >("LuaOnEnable"); luaOnDisable = table.Get <LuaAction <LuaTable> >("LuaOnDisable"); luaOnDestroy = table.Get <LuaAction <LuaTable> >("LuaOnDestroy"); return(table); }
public void Init(string scriptName) { scriptEnv = LuaApplicationFacade.luaEnv.NewTable(); LuaTable meta = LuaApplicationFacade.luaEnv.NewTable(); meta.Set("__index", LuaApplicationFacade.luaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); // 加载lua script LuaApplicationFacade.luaEnv.DoString("require " + "'" + scriptName + "'", "LuaComponent", scriptEnv); scriptEnv.SetInPath <MonoBehaviour>(scriptName + ".self", this); luaStart = scriptEnv.GetInPath <Action>(scriptName + ".start"); luaUpdate = scriptEnv.GetInPath <Action>(scriptName + ".update"); luaOnDestroy = scriptEnv.GetInPath <Action>(scriptName + ".ondestroy"); LuaAwake luaAwake = scriptEnv.GetInPath <LuaAwake>(scriptName + ".awake"); if (null != luaAwake) { luaAwake(this.gameObject); } }