From d79ecb432a47e4790ab91c80a1ca28a21549c18d Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 18 Oct 2014 12:50:40 +1300 Subject: [PATCH] Write Lua debug information to lua.log. --- OpenRA.Game/Scripting/ScriptContext.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Scripting/ScriptContext.cs b/OpenRA.Game/Scripting/ScriptContext.cs index 456ea60923..a1c8f85d4a 100644 --- a/OpenRA.Game/Scripting/ScriptContext.cs +++ b/OpenRA.Game/Scripting/ScriptContext.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -118,6 +119,8 @@ namespace OpenRA.Scripting { runtime = new MemoryConstrainedLuaRuntime(); + Log.AddChannel("lua", "lua.log"); + World = world; WorldRenderer = worldRenderer; knownActorCommands = Game.modData.ObjectCreator @@ -141,7 +144,7 @@ namespace OpenRA.Scripting using (var registerGlobal = (LuaFunction)runtime.Globals["RegisterSandboxedGlobal"]) { - using (var fn = runtime.CreateFunctionFromDelegate((Action)Console.WriteLine)) + using (var fn = runtime.CreateFunctionFromDelegate((Action)LogDebugMessage)) registerGlobal.Call("print", fn).Dispose(); // Register global tables @@ -173,11 +176,22 @@ namespace OpenRA.Scripting } } + void LogDebugMessage(string message) + { + Console.WriteLine("Lua debug: {0}", message); + Log.Write("lua", message); + } + public bool FatalErrorOccurred { get; private set; } public void FatalError(string message) { + var stacktrace = new StackTrace().ToString(); Console.WriteLine("Fatal Lua Error: {0}", message); - Game.AddChatLine(Color.White, "Fatal Lua Error", message); + Console.WriteLine(stacktrace); + + Log.Write("lua", "Fatal Lua Error: {0}", message); + Log.Write("lua", stacktrace); + FatalErrorOccurred = true; }