/// <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) { string msg = ""; if (Lua.lua_isstring(luaState, -1) == 1) { msg = Lua.lua_tostring(luaState, -1); } else if (Lua.lua_isnumber(luaState, -1) == 1 || Lua.lua_isboolean(luaState, -1) || Lua.lua_iscfunction(luaState, -1) || Lua.lua_isfunction(luaState, -1) || Lua.lua_isthread(luaState, -1) || Lua.lua_istable(luaState, -1) ) { msg = "Unknown Lua Error"; } else { 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) { msg = "Unknown Lua Error"; } else { msg = err.ToString(); } } throw new LuaException(msg); }
/// <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()); }