//加载全部Lua模块 internal IEnumerator UF_InitFramework() { if (!m_IsInited) { Debugger.UF_Log("LuaFramework -> Start"); m_Luastate = new GLuaState(); //第三方库 //m_Luastate.OpenLibs(LuaDLL.luaopen_struct); m_Luastate.OpenLibs(LuaDLL.luaopen_lpeg); //m_Luastate.OpenLibs(LuaDLL.luaopen_bit); m_Luastate.LuaSetTop(0); //加载基础库 UF_LuaBaseStart(m_Luastate); //静态绑定 LuaBinder.Bind(m_Luastate); //自定义绑定 LuaCustomBinder.UF_Bind(m_Luastate); yield return(null); //开启一个加载线程加载全部Runtime.Lua模块 Thread thread = new Thread(new ThreadStart(UF_InitLuaModules)); thread.Start(); //主线程等待全部Lua加载 while (!m_IsInited) { yield return(null); } yield return(null); m_Luastate.Collect(); System.GC.Collect(); yield return(null); //获取固有方法 lfHandleNetMsg = m_Luastate.GetFunction("OnHandleProtocol"); lfHandleEventMsg = m_Luastate.GetFunction("OnHandleEvent"); //模块加载完成,主函数启动 UF_CallLuaFunction("MainAwake"); yield return(null); } else { Debugger.UF_Warn("LuaFramework is already Init"); } yield break; }
public void UF_OnUpdate() { if (m_IsInited) { //协议更新 LuaNetwork.UF_Update(lfHandleNetMsg); if (m_Luastate.LuaUpdate(GTime.DeltaTime, GTime.UnscaleDeltaTime) != 0) { string error = m_Luastate.LuaToString(-1); m_Luastate.LuaPop(2); throw new LuaException(error, LuaException.GetLastError()); } m_Luastate.LuaPop(1); m_Luastate.Collect(); UF_UpdateMouseInput(); } }