상속: System.Exception
예제 #1
0
 public LuaException(string msg, Exception e = null, int skip = 1) : base(msg)
 {
     if (e != null)
     {
         if (e is LuaException)
         {
             this._stack = e.get_StackTrace();
         }
         else
         {
             StackTrace    stackTrace    = new StackTrace(e, true);
             StringBuilder stringBuilder = new StringBuilder();
             LuaException.ExtractFormattedStackTrace(stackTrace, stringBuilder, null);
             StackTrace trace = new StackTrace(skip, true);
             LuaException.ExtractFormattedStackTrace(trace, stringBuilder, stackTrace);
             this._stack = stringBuilder.ToString();
         }
     }
     else
     {
         StackTrace    trace2         = new StackTrace(skip, true);
         StringBuilder stringBuilder2 = new StringBuilder();
         LuaException.ExtractFormattedStackTrace(trace2, stringBuilder2, null);
         this._stack = stringBuilder2.ToString();
     }
 }
예제 #2
0
        // TODO 加载流程还不熟悉
        // DoFile是直接加载,然后执行
        // 但是Require是走lua内存机制,内部会缓存,加载时会回调加载,然后内部执行(具体流程没看)
        static int Loader(IntPtr L)
        {
            try
            {
                string fileName = LuaDLL.lua_tostring(L, 1);
                fileName = fileName.Replace(".", "/");
                byte[] buffer = LuaFileUtils.Instance.ReadFile(fileName);
                if (buffer == null)
                {
                    string error = LuaFileUtils.Instance.FindFileError(fileName);
                    LuaDLL.lua_pushstring(L, error);
                    return(1);
                }

                if (LuaConst.openLuaDebugger)
                {
                    fileName = LuaFileUtils.Instance.FindFile(fileName);
                }

                if (LuaDLL.luaL_loadbuffer(L, buffer, buffer.Length, "@" + fileName) != 0)
                {
                    string err = LuaDLL.lua_tostring(L, -1);
                    throw new LuaException(err, LuaException.GetLastError());
                }

                return(1);
            }
            catch (Exception e)
            {
                return(LuaDLL.toluaL_exception(L, e));
            }
        }
예제 #3
0
 public void Call(int nArgs, int errfunc, int top)
 {
     if (LuaDLL.lua_pcall(L, nArgs, LuaDLL.LUA_MULTRET, errfunc) != 0)
     {
         string error = LuaDLL.lua_tostring(L, -1);
         throw new LuaException(error, LuaException.GetLastError());
     }
 }
예제 #4
0
 public void PCall(int args, int oldTop)
 {
     if (LuaDLL.lua_pcall(L, args, LuaDLL.LUA_MULTRET, oldTop) != 0)
     {
         string error = LuaToString(-1);
         throw new LuaException(error, LuaException.GetLastError());
     }
 }
예제 #5
0
        public bool LuaDoFile(string fileName)
        {
            int newTop = this.LuaGetTop();

            if (LuaDLL.luaL_dofile(this.L, fileName))
            {
                return(true);
            }
            string msg = this.LuaToString(-1);

            this.LuaSetTop(newTop);
            throw new LuaException(msg, LuaException.GetLastError(), 1);
        }
예제 #6
0
        public bool LuaDoFile(string fileName)
        {
            int top = LuaGetTop();

            if (LuaDLL.luaL_dofile(L, fileName))
            {
                return(true);
            }

            string err = LuaToString(-1);

            LuaSetTop(top);
            throw new LuaException(err, LuaException.GetLastError());
        }
예제 #7
0
파일: Lua.cs 프로젝트: weimingtom/pap2
        // steffenj: BEGIN Lua 5.1.1 API change (luaopen_* replaced by luaL_openlibs)

        /*
         * Open Lua libraries
         */
        /*
         * public void OpenLibs()
         * {
         *      //LuaDLL.luaL_openlibs(luaState);
         * }
         * public void OpenBaseLib()
         * {
         * }
         * public void OpenIOLib()
         * {
         *      //LuaDLL.luaopen_io(luaState);
         * }
         * public void OpenMathLib()
         * {
         *      //LuaDLL.luaopen_math(luaState);
         * }
         * public void OpenStringLib()
         * {
         *      //LuaDLL.luaopen_string(luaState);
         * }
         * public void OpenTableLib()
         * {
         *      //LuaDLL.luaopen_table(luaState);
         * }
         * public void OpenDebugLib()
         * {
         *      //LuaDLL.luaopen_debug(luaState);
         * }
         * public void OpenLoadLib()
         * {
         *      //LuaDLL.luaopen_loadlib(luaState);
         * }
         */
        // steffenj: END Lua 5.1.1 API change (luaopen_* replaced by luaL_openlibs)


        /// <summary>
        /// Assuming we have a Lua error string sitting on the stack, throw a C# exception out to the user's app
        /// </summary>
        void ThrowExceptionFromError(int oldTop)
        {
            object err = translator.getObject(luaState, -1);

            LuaDLL.lua_settop(luaState, oldTop);

            // If the 'error' on the stack is an actual C# exception, just rethrow it.  Otherwise the value must have started
            // as a true Lua error and is best interpreted as a string - wrap it in a LuaException and rethrow.
            Exception thrown = err as Exception;

            if (thrown == null)
            {
                thrown = new LuaException(err.ToString());
            }

            throw thrown;
        }
예제 #8
0
        /// <summary>
        /// Assuming we have a Lua error string sitting on the stack, throw a C# exception out to the user's app
        /// </summary>
        /// <exception cref="LuaScriptException">Thrown if the script caused an exception</exception>
        void ThrowExceptionFromError(int oldTop)
        {
            object err = translator.getObject(luaState, -1);

            LuaDLL.lua_settop(luaState, oldTop);

            // A pre-wrapped exception - just rethrow it (stack trace of InnerException will be preserved)
            LuaException luaEx = err as LuaException;

            if (luaEx != null)
            {
                throw luaEx;
            }

            // A non-wrapped Lua error (best interpreted as a string) - wrap it and throw it
            if (err == null)
            {
                err = "Unknown Lua Error";
            }
            throw new LuaException(err.ToString());
        }
예제 #9
0
 public void PrintError(LuaException e)
 {
     System.Console.Error.WriteLine(">>A Lua Exception occured:");
     System.Console.Error.WriteLine(">>" + e.Message);
 }
예제 #10
0
 private void ThrowExceptionFromError(int oldTop)
 {
     object obj2 = this.translator.getObject(this.luaState, -1);
     LuaJIT.lua_settop(this.luaState, oldTop);
     Exception exception = obj2 as Exception;
     if (exception == null)
     {
         if (obj2 == null)
         {
             obj2 = "Unknown Lua Error";
         }
         exception = new LuaException(obj2.ToString());
     }
     throw exception;
 }
예제 #11
0
		// steffenj: BEGIN Lua 5.1.1 API change (luaopen_* replaced by luaL_openlibs)
		/*
		 * Open Lua libraries
		 */
		/*
		public void OpenLibs() 
		{
			//LuaDLL.luaL_openlibs(luaState);
		}
		public void OpenBaseLib() 
		{
		}
		public void OpenIOLib() 
		{
			//LuaDLL.luaopen_io(luaState);
		}
		public void OpenMathLib() 
		{
			//LuaDLL.luaopen_math(luaState);
		}
		public void OpenStringLib() 
		{
			//LuaDLL.luaopen_string(luaState);
		}
		public void OpenTableLib() 
		{
			//LuaDLL.luaopen_table(luaState);
		}
		public void OpenDebugLib() 
		{
			//LuaDLL.luaopen_debug(luaState);
		}
		public void OpenLoadLib() 
		{
			//LuaDLL.luaopen_loadlib(luaState);
		}
		*/
		// steffenj: END Lua 5.1.1 API change (luaopen_* replaced by luaL_openlibs)


        /// <summary>
        /// Assuming we have a Lua error string sitting on the stack, throw a C# exception out to the user's app
        /// </summary>
        void ThrowExceptionFromError(int oldTop)
        {
            object err = translator.getObject(luaState, -1);
            LuaDLL.lua_settop(luaState, oldTop);

            // If the 'error' on the stack is an actual C# exception, just rethrow it.  Otherwise the value must have started
            // as a true Lua error and is best interpreted as a string - wrap it in a LuaException and rethrow.
            Exception thrown = err as Exception;

            if(thrown == null)
                thrown = new LuaException(err.ToString());

            throw thrown;
        }
예제 #12
0
 /// <summary>
 /// Handles a lua exception
 /// </summary>
 private void HandleException(LuaException ex)
 {
     Launch.Log("[Lua] *** EXCEPTION *** at " + ex.Source + ": " + ex.Message);
     foreach (var v in ex.Data)
         Launch.Log("[Lua] " + v);
     LKernel.GetG<LuaConsoleManager>().AddLabel("ERROR: " + ex.Message);
     Launch.Log(ex.StackTrace);
 }
예제 #13
0
 public void LuaError(LuaException e)
 {
     NameValueCollection settings = FileHandler.GetAppSettings();
     fatalError("A fatal error occured! \n\nLine " + e.Message.Substring(17) + "\n" + e.StackTrace + "\nIf you can, please tweet this information to " + settings["twitterName"] + ", and it will be fixed ASAP.\n\nThanks!");
 }