Exemplo n.º 1
0
        /*
         * Excutes a Lua file and returns all the chunk's return
         * values in an array
         */
        public object[] DoFile(string fileName, LuaTable env)
        {
            LuaDLL.lua_pushstdcallcfunction(L, tracebackFunction);
            int oldTop = LuaDLL.lua_gettop(L);

            // Load with Unity3D resources
            Debug.Log("fileName==" + fileName);
            byte[] text = LuaStatic.DefaultLoader(fileName);

            if (text == null)
            {
                Debug.LogError("lua dofile failed which path is:::" + fileName + "开始尝试Resources文件夹下加载");
                text = ResLoadAsset(fileName);
                if (text == null)
                {
                    LuaDLL.lua_pop(L, 1);
                    Debug.LogError("lua dofile failed which path is:::" + fileName + "尝试Resources文件夹下加载失败!!!!,移动端路径错误!!!!");
                    return(null);
                }
            }
            else
            {
                Debug.LogError("text != null 长度:" + text.Length);
            }

            //Encoding.UTF8.GetByteCount(text)
            if (LuaDLL.luaL_loadbuffer(L, text, text.Length, fileName) == 0)
            {
                if (env != null)
                {
                    env.push(L);
                    //LuaDLL.lua_setfenv(L, -1);
                    LuaDLL.lua_setfenv(L, -2);
                }

                if (LuaDLL.lua_pcall(L, 0, -1, -2) == 0)
                {
                    object[] results = translator.popValues(L, oldTop);
                    LuaDLL.lua_pop(L, 1);
                    return(results);
                }
                else
                {
                    ThrowExceptionFromError(oldTop);
                    LuaDLL.lua_pop(L, 1);
                }
            }
            else
            {
                ThrowExceptionFromError(oldTop);
                LuaDLL.lua_pop(L, 1);
            }

            return(null);            // Never reached - keeps compiler happy
        }
Exemplo n.º 2
0
        public static int loader(IntPtr L)
        {
            // Get script to load
            string fileName = String.Empty;

            fileName  = LuaDLL.lua_tostring(L, 1);
            fileName  = fileName.Replace('.', '/');
            fileName += ".lua";

            /*
             * // Load with Unity3D resources
             * byte[] text = Load(fileName);
             *
             * if( text == null )
             * {
             *  return 0;
             * }
             * LuaDLL.luaL_loadbuffer(L, text, text.Length, fileName);
             */
            LuaScriptMgr mgr = LuaScriptMgr.GetMgrFromLuaState(L);

            if (mgr == null)
            {
                return(0);
            }

            LuaDLL.lua_pushstdcallcfunction(L, mgr.lua.tracebackFunction);
            int oldTop = LuaDLL.lua_gettop(L);

            byte[] text = LuaStatic.DefaultLoader(fileName);
            if (text == null)
            {
                if (!fileName.Contains("mobdebug"))
                {
                    Debugger.LogError("Loader lua file failed: {0}", fileName);
                }
                LuaDLL.lua_pop(L, 1);
                return(0);
            }
            if (LuaDLL.luaL_loadbuffer(L, text, text.Length, fileName) != 0)
            {
                mgr.lua.ThrowExceptionFromError(oldTop);
                LuaDLL.lua_pop(L, 1);
            }
            return(1);
        }