Пример #1
0
        public static int loader(IntPtr L)
        {
            string fileName = string.Empty;

            fileName = LuaAPI.lua_tostring(L, 1);

            string lowerName = fileName.ToLower();

            if (lowerName.EndsWith(".lua"))
            {
                int index = fileName.LastIndexOf('.');
                fileName = fileName.Substring(0, index);
            }
            fileName = fileName.Replace('.', '/');
            int oldTop = LuaAPI.lua_gettop(L);

            LuaAPI.lua_pushstdcallcfunction(L, LuaStatic.traceback);

            byte[] text = LuaStatic.Load(fileName);
            if (text == null)
            {
                LuaAPI.lua_pop(L, 1);
                return(0);
            }
            if (LuaAPI.luaL_loadbuffer(L, text, text.Length, fileName) != 0)
            {
                LuaScriptMgr mgr = LuaScriptMgr.GetMgrFromLuaState(L);
                if (mgr != null)
                {
                    mgr.lua.ThrowExceptionFromError(oldTop + 1);
                }
                LuaAPI.lua_pop(L, 1);
            }
            return(1);
        }
Пример #2
0
        public void Release()
        {
            if (_Disposed || name == null)
            {
                return;
            }

            --count;

            if (count > 0)
            {
                return;
            }

            if (name != null)
            {
                LuaScriptMgr mgr = LuaScriptMgr.GetMgrFromLuaState(_Interpreter.L);

                if (mgr != null)
                {
                    mgr.RemoveLuaRes(name);
                }
            }

            Dispose();
        }
Пример #3
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";

            string lowerName = fileName.ToLower();

            if (lowerName.EndsWith(".lua"))
            {
                int index = fileName.LastIndexOf('.');
                fileName = fileName.Substring(0, index);
            }
            fileName = fileName.Replace('.', '/') + ".lua";
            fileName = fileName.Replace(".lua", ".txt");

            /*
             * // 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.Load(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);
        }
Пример #4
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.Load(fileName);
            if (text == null)
            {
                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);
        }
Пример #5
0
        public static int loader(IntPtr L)
        {
            string text = string.Empty;

            text = LuaDLL.lua_tostring(L, 1);
            string text2 = text.ToLower();

            if (text2.EndsWith(".lua"))
            {
                int length = text.LastIndexOf('.');
                text = text.Substring(0, length);
            }
            text = text.Replace('.', '/') + ".lua";
            LuaScriptMgr mgrFromLuaState = LuaScriptMgr.GetMgrFromLuaState(L);

            if (mgrFromLuaState == null)
            {
                return(0);
            }
            LuaDLL.lua_pushstdcallcfunction(L, mgrFromLuaState.lua.tracebackFunction, 0);
            int oldTop = LuaDLL.lua_gettop(L);

            byte[] array = LuaStatic.Load(text);
            if (array == null)
            {
                if (!text.Contains("mobdebug"))
                {
                    Debugger.LogError("Loader lua file failed: {0}", new object[]
                    {
                        text
                    });
                }
                LuaDLL.lua_pop(L, 1);
                return(0);
            }
            if (LuaDLL.luaL_loadbuffer(L, array, array.Length, text) != 0)
            {
                mgrFromLuaState.lua.ThrowExceptionFromError(oldTop);
                LuaDLL.lua_pop(L, 1);
            }
            return(1);
        }
Пример #6
0
 public void Release()
 {
     if (this._Disposed || this.name == null)
     {
         this.Dispose();
         return;
     }
     this.count--;
     if (this.count > 0)
     {
         return;
     }
     if (this.name != null)
     {
         LuaScriptMgr mgrFromLuaState = LuaScriptMgr.GetMgrFromLuaState(this._Interpreter.L);
         if (mgrFromLuaState != null)
         {
             mgrFromLuaState.RemoveLuaRes(this.name);
         }
     }
     this.Dispose();
 }
Пример #7
0
        public virtual void Dispose(bool disposeManagedResources)
        {
            if (!_Disposed)
            {
                if (_Reference != 0 && _Interpreter != null)
                {
                    if (disposeManagedResources)
                    {
                        _Interpreter.dispose(_Reference);
                    }
                    else
                    {
                        LuaScriptMgr mgr = LuaScriptMgr.GetMgrFromLuaState(_Interpreter.L);
                        mgr.refGCList.Enqueue(_Reference);
                    }

                    _Reference = 0;
                }

                _Interpreter = null;
                _Disposed    = true;
            }
        }