Ejemplo n.º 1
0
 public void Init()
 {
     Log.i("Lua init begin");
     if (!dirty)
     {
         return;
     }
     //====================
     if (mL != null)
     {            //释放以便重加载
         Log.i("Lua Dispose");
         mL.Dispose();
         mL = null;
     }
     //====================
     LUA_PATH     = ResLoad.resPath + "/lua/";
     mReadLuaFile = readLuaFile;
     if (!Directory.Exists(LUA_PATH))
     {
         LUA_PATH = Application.streamingAssetsPath + "/Lua/";                //路径区分大小写
                         #if UNITY_ANDROID && !UNITY_EDITOR
         mReadLuaFile = readAssetLuaFile;
                         #endif
     }
     //====================
                 #if USE_ULUA
     mL = new LuaState();
     bindLuaClass(this);
                 #elif USE_XLUA
     mL = new LuaEnv();
     mL.AddLoader(LuaLoader);
     //引入第三方lua库
     mL.AddBuildin("rapidjson", XLua.LuaDLL.Lua.LoadRapidJson);
     mL.AddBuildin("lpeg", XLua.LuaDLL.Lua.LoadLpeg);
     mL.AddBuildin("pb", XLua.LuaDLL.Lua.LoadLuaProfobuf);
     //mL.AddBuildin("ffi", XLua.LuaDLL.Lua.LoadFFI);IOS存在兼容问题
                 #endif
     LuaHelp.ExportToLua();
     byte[] tags = mReadLuaFile(LUA_PATH + "main.lua", false);
     mEncode = tags [2] == 0x3d ? false : true;
     //====================
     //设置Lua脚本根路径列表,并执行入口脚本main.lua
     mL.DoString("package.path = package.path .. ';' .. '" + LUA_PATH + "?.lua';require 'main';");
     //====================
     mNewLuaObject    = (LuaFunction)mL["newLuaObject"];
     mReloadLua       = (LuaFunction)mL["reloadLua"];
     mPushLuaEvent    = (LuaFunction)mL["pushLuaEvent"];
     mProcessLuaEvent = (LuaFunction)mL["processLuaEvent"];
     mGameConfig      = (LuaTable)mL["LGameConfig"];
     ((LuaFunction)mL ["main"]).Call();
     //====================
     dirty = false;
     Log.i("Lua init end");
 }
Ejemplo n.º 2
0
        //private static int trace = 0;

        static LuaStatic()
        {
            Load = DefaultLoader;
        }
Ejemplo n.º 3
0
 //private static int trace = 0;
 static LuaStatic()
 {
     Load = DefaultLoader;
 }
Ejemplo n.º 4
0
 static LuaStatic()
 {
     LuaStatic.init_luanet = "local metatable = {}\n            local rawget = rawget\n            local debug = debug\n            local import_type = luanet.import_type\n            local load_assembly = luanet.load_assembly\n            luanet.error, luanet.type = error, type\n            -- Lookup a .NET identifier component.\n            function metatable:__index(key) -- key is e.g. 'Form'\n            -- Get the fully-qualified name, e.g. 'System.Windows.Forms.Form'\n            local fqn = rawget(self,'.fqn')\n            fqn = ((fqn and fqn .. '.') or '') .. key\n\n            -- Try to find either a luanet function or a CLR type\n            local obj = rawget(luanet,key) or import_type(fqn)\n\n            -- If key is neither a luanet function or a CLR type, then it is simply\n            -- an identifier component.\n            if obj == nil then\n                -- It might be an assembly, so we load it too.\n                    pcall(load_assembly,fqn)\n                    obj = { ['.fqn'] = fqn }\n            setmetatable(obj, metatable)\n            end\n\n            -- Cache this lookup\n            rawset(self, key, obj)\n            return obj\n            end\n\n            -- A non-type has been called; e.g. foo = System.Foo()\n            function metatable:__call(...)\n            error('No such type: ' .. rawget(self,'.fqn'), 2)\n            end\n\n            -- This is the root of the .NET namespace\n            luanet['.fqn'] = false\n            setmetatable(luanet, metatable)\n\n            -- Preload the mscorlib assembly\n            luanet.load_assembly('mscorlib')\n\n            function traceback(msg)                \n                return debug.traceback(msg, 1)                \n            end";
     LuaStatic.Load        = new ReadLuaFile(LuaStatic.DefaultLoader);
 }