Pass Lua Console log callback to LuaCanvas and replace static calls

This commit is contained in:
YoshiRulz 2020-11-26 22:35:52 +10:00
parent 72fd3f2fca
commit 9e0a3c0e34
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 13 additions and 10 deletions

View File

@ -13,8 +13,11 @@ namespace BizHawk.Client.EmuHawk
[Description("Represents a canvas object returned by the gui.createcanvas() method")]
public partial class LuaCanvas : Form
{
public LuaCanvas(int width, int height, int? x = null, int? y = null)
private readonly Action<string> LogOutputCallback;
public LuaCanvas(int width, int height, int? x, int? y, Action<string> logOutputCallback)
{
LogOutputCallback = logOutputCallback;
InitializeComponent();
luaPictureBox.Image = Properties.Resources.LuaPictureBox;
luaPictureBox.Width = width;
@ -117,7 +120,7 @@ namespace BizHawk.Client.EmuHawk
}
catch (Exception ex)
{
ConsoleLuaLibrary.Log(ex.Message);
LogOutputCallback(ex.Message);
}
}
@ -134,7 +137,7 @@ namespace BizHawk.Client.EmuHawk
}
catch (Exception ex)
{
ConsoleLuaLibrary.Log(ex.Message);
LogOutputCallback(ex.Message);
}
}
@ -151,7 +154,7 @@ namespace BizHawk.Client.EmuHawk
}
catch (Exception ex)
{
ConsoleLuaLibrary.Log(ex.Message);
LogOutputCallback(ex.Message);
}
}
@ -168,7 +171,7 @@ namespace BizHawk.Client.EmuHawk
}
catch (Exception ex)
{
ConsoleLuaLibrary.Log(ex.Message);
LogOutputCallback(ex.Message);
}
}
@ -181,7 +184,7 @@ namespace BizHawk.Client.EmuHawk
{
if (!File.Exists(path))
{
ConsoleLuaLibrary.Log($"File not found: {path}\nScript Terminated");
LogOutputCallback($"File not found: {path}\nScript Terminated");
return;
}
@ -207,7 +210,7 @@ namespace BizHawk.Client.EmuHawk
{
if (!File.Exists(path))
{
ConsoleLuaLibrary.Log($"File not found: {path}\nScript Terminated");
LogOutputCallback($"File not found: {path}\nScript Terminated");
return;
}
@ -276,7 +279,7 @@ namespace BizHawk.Client.EmuHawk
}
catch (Exception ex)
{
ConsoleLuaLibrary.Log(ex.Message);
LogOutputCallback(ex.Message);
}
}
@ -293,7 +296,7 @@ namespace BizHawk.Client.EmuHawk
}
catch (Exception ex)
{
ConsoleLuaLibrary.Log(ex.Message);
LogOutputCallback(ex.Message);
}
}

View File

@ -77,7 +77,7 @@ namespace BizHawk.Client.EmuHawk
{
guiLib.CreateLuaCanvasCallback = (width, height, x, y) =>
{
var canvas = new LuaCanvas(width, height, x, y);
var canvas = new LuaCanvas(width, height, x, y, LogToLuaConsole);
canvas.Show();
return _lua.TableFromObject(canvas);
};