Example #1
0
        public IEnumerator Init()
        {
#if SLUA
            int frameCount = 0;
            while (!_luaSvr.inited)
            {
                if (frameCount % 30 == 0)
                {
                    Log.LogWarning("SLua Initing...");
                }
                yield return(null);

                frameCount++;
            }
            var L = _luaSvr.luaState.L;
            LuaDLL.lua_pushcfunction(L, LuaImport);
            LuaDLL.lua_setglobal(L, "import");
            LuaDLL.lua_pushcfunction(L, LuaUsing);
            LuaDLL.lua_setglobal(L, "using");       // same as SLua's import, using namespace
            LuaDLL.lua_pushcfunction(L, ImportCSharpType);
            LuaDLL.lua_setglobal(L, "import_type"); // same as SLua's SLua.GetClass(), import C# type
#else
            var L = _luaEnv.L;
            LuaDLL.lua_pushstdcallcfunction(L, LuaImport);
            LuaDLL.xlua_setglobal(L, "import");

            //TODO lua中需要require的第三方库加到这里
            _luaEnv.AddBuildin("rapidjson", XLua.LuaDLL.Lua.LoadRapidJson);
            _luaEnv.AddBuildin("lpeg", XLua.LuaDLL.Lua.LoadLpeg);
            _luaEnv.AddBuildin("pb", XLua.LuaDLL.Lua.LoadLuaProfobuf);
            _luaEnv.AddBuildin("ffi", XLua.LuaDLL.Lua.LoadFFI);
            yield return(null);
#endif

            CallScript("Init");

            IsInited = true;
        }
Example #2
0
        public void InitSLua()
        {
#if SLUA
            int frameCount = 0;
            while (!_luaSvr.inited)
            {
                if (frameCount % 30 == 0)
                {
                    Log.LogWarning("SLua Initing...");
                }
                yield return(null);

                frameCount++;
            }
            var L = _luaSvr.luaState.L;
            LuaDLL.lua_pushcfunction(L, LuaImport);
            LuaDLL.lua_setglobal(L, "import");
            LuaDLL.lua_pushcfunction(L, LuaUsing);
            LuaDLL.lua_setglobal(L, "using");       // same as SLua's import, using namespace
            LuaDLL.lua_pushcfunction(L, ImportCSharpType);
            LuaDLL.lua_setglobal(L, "import_type"); // same as SLua's SLua.GetClass(), import C# type
#endif
        }