Esempio n. 1
0
		/*
         * Passes errors (argument e) to the Lua interpreter
         */
		internal void throwError(IntPtr luaState, object e)
		{
			// We use this to remove anything pushed by luaL_where
			int oldTop = LuaDLL.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
			LuaDLL.luaL_where(luaState, 1);
			object[] curlev = popValues(luaState, oldTop);
			
			// Determine the position in the script where the exception was triggered
			string errLocation = "";
			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
			{
				Exception 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);
			LuaDLL.lua_error(luaState);
		}
Esempio n. 2
0
        /// <summary>[-0, +0, v] Passes errors (argument e) to the Lua interpreter. This function throws a Lua exception, and therefore never returns.</summary>
        internal int throwError(lua.State L, Exception ex)
        {
            Debug.Assert(interpreter.IsSameLua(L));
            Debug.Assert(ex != null);
            luaL.checkstack(L, 1, "ObjectTranslator.throwError");
            // Determine the position in the script where the exception was triggered
            // Stack frame #0 is our C# wrapper, so not very interesting to the user
            // Stack frame #1 must be the lua code that called us, so that's what we want to use
            string errLocation = luanet.where (L, 1);

            // Wrap generic .NET exception as an InnerException and store the error location
            ex = new LuaScriptException(ex, errLocation);

            // don't need to check the stack, same pattern as luaL_error
            push(L, ex);
            return(lua.error(L));
        }
Esempio n. 3
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(), "");
        }
Esempio n. 4
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);
        }