From e88b7cc93e2233c334e71272a279eeddc8d05be6 Mon Sep 17 00:00:00 2001 From: adelikat Date: Wed, 21 May 2014 01:15:52 +0000 Subject: [PATCH] one more tweak to make lua library constructors unified --- BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs | 17 ++++++----------- .../tools/Lua/Libraries/EmuLuaLibrary.cs | 16 +++++++++++----- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs index 00bd67cdda..abb7d0424d 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs @@ -13,8 +13,10 @@ namespace BizHawk.Client.Common { public class EmulatorLuaLibrary : LuaLibraryBase { - private readonly Action _frameAdvanceCallback; - private readonly Action _yieldCallback; + public Action FrameAdvanceCallback { get; set; } + public Action YieldCallback { get; set; } + + public EmulatorLuaLibrary(Lua lua) : base(lua) { } @@ -22,13 +24,6 @@ namespace BizHawk.Client.Common public EmulatorLuaLibrary(Lua lua, Action logOutputCallback) : base(lua, logOutputCallback) { } - public EmulatorLuaLibrary(Lua lua, Action logOutputCallback, Action frameAdvanceCallback, Action yieldCallback) - : this(lua, logOutputCallback) - { - _frameAdvanceCallback = frameAdvanceCallback; - _yieldCallback = yieldCallback; - } - public override string Name { get { return "emu"; } } [LuaMethodAttributes( @@ -46,7 +41,7 @@ namespace BizHawk.Client.Common )] public void FrameAdvance() { - _frameAdvanceCallback(); + FrameAdvanceCallback(); } [LuaMethodAttributes( @@ -180,7 +175,7 @@ namespace BizHawk.Client.Common )] public void Yield() { - _yieldCallback(); + YieldCallback(); } [LuaMethodAttributes( diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs index 11884277fa..1065c7aab2 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs @@ -29,8 +29,12 @@ namespace BizHawk.Client.EmuHawk _caller = passed.Get(); // Register lua libraries + _lua.RegisterFunction("print", this, GetType().GetMethod("Print")); + // TODO: Search the assemblies for objects that inherit LuaBaseLibrary, and instantiate and register them and put them into an array, + // rather than call them all by name here + _formsLibrary = new FormsLuaLibrary(_lua, ConsoleLuaLibrary.LogOutput); _formsLibrary.LuaRegister(Docs); @@ -44,11 +48,13 @@ namespace BizHawk.Client.EmuHawk new EmuHawkLuaLibrary(_lua, ConsoleLuaLibrary.LogOutput).LuaRegister(Docs); new ConsoleLuaLibrary(_lua, ConsoleLuaLibrary.LogOutput).LuaRegister(Docs); - new EmulatorLuaLibrary( - _lua, - ConsoleLuaLibrary.LogOutput, - Frameadvance, - EmuYield).LuaRegister(Docs); + var emuLib = new EmulatorLuaLibrary(_lua, ConsoleLuaLibrary.LogOutput) + { + FrameAdvanceCallback = Frameadvance, + YieldCallback = EmuYield + }; + + emuLib.LuaRegister(Docs); new InputLuaLibrary(_lua, ConsoleLuaLibrary.LogOutput).LuaRegister(Docs); new JoypadLuaLibrary(_lua, ConsoleLuaLibrary.LogOutput).LuaRegister(Docs);