internal void ThrowError(ScriptState luaState, object e) { if (Disposed) { return; } // We use this to remove anything pushed by luaL_where int oldTop = LuaCore.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 LuaCore.Where(luaState, 1); var curlev = ObjectMgr.PopResults(luaState, oldTop); // Determine the position in the script where the exception was triggered string errLocation = string.Empty; if (curlev.Count > 0) { errLocation = curlev[0].ToString(); } var message = e as string; if (message != null) { e = new LuaSourcetException(message, errLocation); } else { var ex = e as Exception; if (ex != null) { e = new LuaSourcetException(ex, errLocation); } } ObjectMgr.PushObject(luaState, e); LuaCore.Error(luaState); }