one more tweak to make lua library constructors unified

This commit is contained in:
adelikat 2014-05-21 01:15:52 +00:00
parent 17568997bf
commit e88b7cc93e
2 changed files with 17 additions and 16 deletions

View File

@ -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<string> logOutputCallback)
: base(lua, logOutputCallback) { }
public EmulatorLuaLibrary(Lua lua, Action<string> 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(

View File

@ -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);