Inheritance: 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
ファイル: Lua.cs プロジェクト: zwwl0801/kopiluainterface
        /// <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
ファイル: LuaManager.cs プロジェクト: elefantstudio-se/funked
 public void PrintError(LuaException e)
 {
     System.Console.Error.WriteLine(">>A Lua Exception occured:");
     System.Console.Error.WriteLine(">>" + e.Message);
 }
コード例 #10
0
ファイル: Lua.cs プロジェクト: Evangileon/LuaInterface
 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
ファイル: Lua.cs プロジェクト: Rocket-Buddha/GameCode4
		// 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
ファイル: LuaMain.cs プロジェクト: CisciarpMaster/PonyKart
 /// <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
ファイル: Compiler.cs プロジェクト: omoeym110/Rbx2Source
 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!");
 }