Esempio n. 1
0
        private int LuaUsing(IntPtr l)
        {
            try
            {
                LuaDLL.luaL_checktype(l, 1, LuaTypes.LUA_TSTRING);
                string str = LuaDLL.lua_tostring(l, 1);

                string[] ns = str.Split('.');

                LuaDLL.lua_pushglobaltable(l);

                for (int n = 0; n < ns.Length; n++)
                {
                    LuaDLL.lua_getfield(l, -1, ns[n]);
                    if (!LuaDLL.lua_istable(l, -1))
                    {
                        return(LuaObject.error(l, "expect {0} is type table", ns));
                    }
                    LuaDLL.lua_remove(l, -2);
                }

                LuaDLL.lua_pushnil(l);
                while (LuaDLL.lua_next(l, -2) != 0)
                {
                    string key = LuaDLL.lua_tostring(l, -2);
                    LuaDLL.lua_getglobal(l, key);
                    if (!LuaDLL.lua_isnil(l, -1))
                    {
                        LuaDLL.lua_pop(l, 1);
                        return(LuaObject.error(l, "{0} had existed, import can't overload it.", key));
                    }
                    LuaDLL.lua_pop(l, 1);
                    LuaDLL.lua_setglobal(l, key);
                }

                LuaDLL.lua_pop(l, 1);

                LuaObject.pushValue(l, true);
                return(1);
            }
            catch (Exception e)
            {
                return(LuaObject.error(l, e));
            }
        }
Esempio n. 2
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;
        }
Esempio n. 3
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
        }