Lua - refactor emu library to use the new registration method, documentation is all "TODO"

This commit is contained in:
adelikat 2014-01-25 21:10:51 +00:00
parent 06c0417f96
commit 65d50ca329
3 changed files with 76 additions and 29 deletions

View File

@ -9,6 +9,8 @@ using LuaInterface;
namespace BizHawk.Client.Common
{
using System.Collections.Generic;
public class EmulatorLuaLibrary : LuaLibraryBase
{
public EmulatorLuaLibrary(Lua lua, Action frameAdvanceCallback, Action yieldCallback)
@ -36,7 +38,7 @@ namespace BizHawk.Client.Common
"limitframerate",
"minimizeframeskip",
"setrenderplanes",
"yield",
"yield"
};
}
}
@ -45,26 +47,26 @@ namespace BizHawk.Client.Common
private readonly Action _frameAdvanceCallback;
private readonly Action _yieldCallback;
private static void emu_setrenderplanes_do(object[] lua_p)
private static void SetrenderplanesDo(IList<object> luaParam)
{
if (Global.Emulator is NES)
{
// in the future, we could do something more arbitrary here.
// but this isn't any worse than the old system
var s = (NES.NESSettings)Global.Emulator.GetSettings();
s.DispSprites = (bool)lua_p[0];
s.DispBackground = (bool)lua_p[1];
s.DispSprites = (bool)luaParam[0];
s.DispBackground = (bool)luaParam[1];
Global.Emulator.PutSettings(s);
}
else if (Global.Emulator is PCEngine)
{
var s = (PCEngine.PCESettings)Global.Emulator.GetSettings();
s.ShowOBJ1 = (bool)lua_p[0];
s.ShowBG1 = (bool)lua_p[1];
if (lua_p.Length > 2)
s.ShowOBJ1 = (bool)luaParam[0];
s.ShowBG1 = (bool)luaParam[1];
if (luaParam.Count > 2)
{
s.ShowOBJ2 = (bool)lua_p[2];
s.ShowBG2 = (bool)lua_p[3];
s.ShowOBJ2 = (bool)luaParam[2];
s.ShowBG2 = (bool)luaParam[3];
}
Global.Emulator.PutSettings(s);
@ -72,13 +74,17 @@ namespace BizHawk.Client.Common
else if (Global.Emulator is SMS)
{
var s = (SMS.SMSSettings)Global.Emulator.GetSettings();
s.DispOBJ = (bool)lua_p[0];
s.DispBG = (bool)lua_p[1];
s.DispOBJ = (bool)luaParam[0];
s.DispBG = (bool)luaParam[1];
Global.Emulator.PutSettings(s);
}
}
public static void emu_displayvsync(object boolean)
[LuaMethodAttributes(
"displayvsync",
"TODO"
)]
public static void DisplayVsync(object boolean)
{
var temp = boolean.ToString();
if (!String.IsNullOrWhiteSpace(temp))
@ -94,22 +100,38 @@ namespace BizHawk.Client.Common
}
}
public void emu_frameadvance()
[LuaMethodAttributes(
"frameadvance",
"TODO"
)]
public void FrameAdvance()
{
_frameAdvanceCallback();
}
public static int emu_framecount()
[LuaMethodAttributes(
"framecount",
"TODO"
)]
public static int FrameCount()
{
return Global.Emulator.Frame;
}
public static int emu_getregister(string name)
[LuaMethodAttributes(
"getregister",
"TODO"
)]
public static int GetRegister(string name)
{
return Global.Emulator.GetCpuFlagsAndRegisters().FirstOrDefault(x => x.Key == name).Value;
}
public LuaTable emu_getregisters()
[LuaMethodAttributes(
"getregisters",
"TODO"
)]
public LuaTable GetRegisters()
{
var table = _lua.NewTable();
foreach (var kvp in Global.Emulator.GetCpuFlagsAndRegisters())
@ -120,22 +142,38 @@ namespace BizHawk.Client.Common
return table;
}
public static string emu_getsystemid()
[LuaMethodAttributes(
"getsystemid",
"TODO"
)]
public static string GetSystemId()
{
return Global.Emulator.SystemId;
}
public static bool emu_islagged()
[LuaMethodAttributes(
"islagged",
"TODO"
)]
public static bool IsLagged()
{
return Global.Emulator.IsLagFrame;
}
public static int emu_lagcount()
[LuaMethodAttributes(
"lagcount",
"TODO"
)]
public static int LagCount()
{
return Global.Emulator.LagCount;
}
public static void emu_limitframerate(object boolean)
[LuaMethodAttributes(
"limitframerate",
"TODO"
)]
public static void LimitFramerate(object boolean)
{
var temp = boolean.ToString();
if (!String.IsNullOrWhiteSpace(temp))
@ -151,7 +189,11 @@ namespace BizHawk.Client.Common
}
}
public static void emu_minimizeframeskip(object boolean)
[LuaMethodAttributes(
"minimizeframeskip",
"TODO"
)]
public static void MinimizeFrameskip(object boolean)
{
var temp = boolean.ToString();
if (!String.IsNullOrWhiteSpace(temp))
@ -167,17 +209,25 @@ namespace BizHawk.Client.Common
}
}
public static void emu_setrenderplanes( // For now, it accepts arguments up to 5.
[LuaMethodAttributes(
"setrenderplanes",
"TODO"
)]
public static void SetRenderPlanes( // For now, it accepts arguments up to 5.
object lua_p0,
object lua_p1 = null,
object lua_p2 = null,
object lua_p3 = null,
object lua_p4 = null)
{
emu_setrenderplanes_do(LuaVarArgs(lua_p0, lua_p1, lua_p2, lua_p3, lua_p4));
SetrenderplanesDo(LuaVarArgs(lua_p0, lua_p1, lua_p2, lua_p3, lua_p4));
}
public void emu_yield()
[LuaMethodAttributes(
"yield",
"TODO"
)]
public void Yield()
{
_yieldCallback();
}

View File

@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using BizHawk.Common;
using LuaInterface;
namespace BizHawk.Client.Common

View File

@ -22,7 +22,7 @@ namespace BizHawk.Client.EmuHawk
}
public EmuLuaLibrary(LuaConsole passed)
:this()
: this()
{
LuaWait = new AutoResetEvent(false);
Docs.Clear();
@ -88,7 +88,7 @@ namespace BizHawk.Client.EmuHawk
_lua,
Frameadvance,
EmuYield
).LuaRegister(lua, Docs);
).LuaRegisterNew(lua, Docs);
_eventLibrary.LuaRegister(lua, Docs);
_formsLibrary.LuaRegister(lua, Docs);