Пример #1
0
        internal void Error(Exception e)
        {
            string shortMsg = "Error: " + e.Message.Split(new char[1] {
                '\n'
            }, 2)[0];
            string longMsg = "Error: " + e;

            if (e is LuaScriptException)
            {
                LuaScriptException ex = (LuaScriptException)e;
                if (ex.IsNetException)
                {
                    e = e.InnerException;
                }
                shortMsg = "Error in " + ex.Source + e.Message.Split(new char[1] {
                    '\n'
                }, 2)[0];
                longMsg = "Error in " + ex.Source + e;
            }
            if (errorLog != null)
            {
                File.AppendAllText(errorLog, DateTime.Now.ToString("(HH:mm:ss) ") + longMsg + "\n");
                server.Log(shortMsg);
            }
            else
            {
                server.Log(longMsg);
            }
            if (server.Level != null)
            {
                new Message("&e" + shortMsg).Send(server);
            }
        }
Пример #2
0
        /// <summary>
        /// Returns type and message of the exception and all inner exceptions, but not the stack trace
        /// </summary>
        private string GetShortErrorMessage(LuaScriptException ex)
        {
            var       shortMessage = (ex.Source ?? "") + ex.Message;
            Exception curr         = ex;

            while (curr.InnerException != null)
            {
                curr          = curr.InnerException;
                shortMessage += " ---> " + curr.GetType().FullName + ": " + curr.Message;
            }
            return(shortMessage);
        }
Пример #3
0
        /*
         * Passes errors (argument e) to the Lua interpreter
         */
        internal void ThrowError(LuaState luaState, object e)
        {
            // We use this to remove anything pushed by luaL_where
            int oldTop = luaState.GetTop();

            // Stack frame #1 is our C# wrapper, so not very interesting to the user
            // Stack frame #2 must be the lua code that called us, so that's what we want to use
            luaState.Where(1);
            var curlev = PopValues(luaState, oldTop);

            // Determine the position in the script where the exception was triggered
            string errLocation = string.Empty;

            if (curlev.Length > 0)
            {
                errLocation = curlev[0].ToString();
            }

            string message = e as string;

            if (message != null)
            {
                // Wrap Lua error (just a string) and store the error location
                if (interpreter.UseTraceback)
                {
                    message += Environment.NewLine + interpreter.GetDebugTraceback();
                }
                e = new LuaScriptException(message, errLocation);
            }
            else
            {
                var ex = e as Exception;

                if (ex != null)
                {
                    // Wrap generic .NET exception as an InnerException and store the error location
                    if (interpreter.UseTraceback)
                    {
                        ex.Data["Traceback"] = interpreter.GetDebugTraceback();
                    }
                    e = new LuaScriptException(ex, errLocation);
                }
            }

            Push(luaState, e);
            //luaState.Error();
        }
Пример #4
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)
            LuaScriptException luaEx = err as LuaScriptException;

            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 LuaScriptException(err.ToString(), "");
        }
Пример #5
0
        /*
         * Passes errors (argument e) to the Lua interpreter
         */
        internal void ThrowError(LuaState luaState, object e)
        {
            // We use this to remove anything pushed by luaL_where
            int oldTop = LuaLib.LuaGetTop(luaState);

            // Stack frame #1 is our C# wrapper, so not very interesting to the user
            // Stack frame #2 must be the lua code that called us, so that's what we want to use
            LuaLib.LuaLWhere(luaState, 1);
            var curlev = PopValues(luaState, oldTop);

            // Determine the position in the script where the exception was triggered
            string errLocation = string.Empty;

            if (curlev.Length > 0)
            {
                errLocation = curlev [0].ToString();
            }

            string message = e as string;

            if (message != null)
            {
                // Wrap Lua error (just a string) and store the error location
                e = new LuaScriptException(message, errLocation);
            }
            else
            {
                var ex = e as Exception;

                if (ex != null)
                {
                    // Wrap generic .NET exception as an InnerException and store the error location
                    e = new LuaScriptException(ex, errLocation);
                }
            }

            Push(luaState, e);
            LuaLib.LuaError(luaState);
        }
Пример #6
0
        /*
         * Passes errors (argument e) to the Lua interpreter
         */
        internal void throwError(LuaCore.lua_State luaState, object e)
        {
            // We use this to remove anything pushed by luaL_where
            int oldTop = LuaLib.lua_gettop(luaState);

            // Stack frame #1 is our C# wrapper, so not very interesting to the user
            // Stack frame #2 must be the lua code that called us, so that's what we want to use
            LuaLib.luaL_where(luaState, 1);
            var curlev = popValues(luaState, oldTop);

            // Determine the position in the script where the exception was triggered
            string errLocation = string.Empty;

            if(curlev.Length > 0)
                errLocation = curlev[0].ToString();

            string message = e as string;

            if(!message.IsNull())
            {
                // Wrap Lua error (just a string) and store the error location
                e = new LuaScriptException(message, errLocation);
            }
            else
            {
                var ex = e as Exception;

                if(!ex.IsNull())
                {
                    // Wrap generic .NET exception as an InnerException and store the error location
                    e = new LuaScriptException(ex, errLocation);
                }
            }

            push(luaState, e);
            LuaLib.lua_error(luaState);
        }
Пример #7
0
 static void CheckException(LuaScriptException ex)
 {
     Assert.AreEqual(ErrorMessage, ex.Message);
 }