Beispiel #1
0
        //加载全部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;
        }
Beispiel #2
0
 public void UF_CallLuaFunction(string method)
 {
     if (m_Luastate != null)
     {
         LuaFunction func = m_Luastate.GetFunction(method);
         if (func != null)
         {
             func.Call();
             func.Dispose();
             func = null;
         }
     }
 }
Beispiel #3
0
        public static LuaFunction GetFunction(IntPtr L, int reference)
        {
            GLuaState state = GLuaState.Get(L);

            return(state.GetFunction(reference));
        }