From 21a21ac7b724916b1b09b5d0f324eda7a5fc157c Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 31 Oct 2013 16:20:45 +0000 Subject: [PATCH] make savestate library its own object, also removed savestate.registersave and savestate.registerload (users should now use the events library instead). Todo: update documentation and remove references to these in any checked in lua scripts that might use them --- .../Lua/Libraries/EmuLuaLibrary.Events.cs | 8 ++- .../Lua/Libraries/EmuLuaLibrary.Savestate.cs | 61 +++++++------------ .../tools/Lua/Libraries/EmuLuaLibrary.cs | 21 +------ 3 files changed, 30 insertions(+), 60 deletions(-) diff --git a/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.Events.cs b/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.Events.cs index 8226bcd200..e13d400de2 100644 --- a/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.Events.cs +++ b/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.Events.cs @@ -121,7 +121,9 @@ namespace BizHawk.MultiClient public string event_onloadstate(LuaFunction luaf, object name = null) { - return savestate_registerload(luaf, name); + NamedLuaFunction nlf = new NamedLuaFunction(luaf, "OnSavestateLoad", name != null ? name.ToString() : null); + lua_functions.Add(nlf); + return nlf.GUID.ToString(); } public void event_onmemoryread(LuaFunction luaf, object address = null) @@ -199,7 +201,9 @@ namespace BizHawk.MultiClient public string event_onsavestate(LuaFunction luaf, object name = null) { - return savestate_registersave(luaf, name); + NamedLuaFunction nlf = new NamedLuaFunction(luaf, "OnSavestateSave", name != null ? name.ToString() : null); + lua_functions.Add(nlf); + return nlf.GUID.ToString(); } public bool event_unregisterbyid(object guid) diff --git a/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.Savestate.cs b/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.Savestate.cs index 09d8439e7b..5b2f5ef1d9 100644 --- a/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.Savestate.cs +++ b/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.Savestate.cs @@ -4,8 +4,23 @@ using BizHawk.Client.Common; namespace BizHawk.MultiClient { - public partial class EmuLuaLibrary + public class SavestateLuaLibrary : LuaLibraryBase { + public override string Name { get { return "savestate"; } } + public override string[] Functions + { + get + { + return new[] + { + "load", + "loadslot", + "save", + "saveslot", + }; + } + } + public void savestate_load(object lua_input) { if (lua_input is string) @@ -16,35 +31,12 @@ namespace BizHawk.MultiClient public void savestate_loadslot(object lua_input) { - int x; + int slot = LuaInt(lua_input); - try //adelikat: This crap might not be necessary, need to test for a more elegant solution + if (slot >= 0 && slot <= 9) { - x = int.Parse(lua_input.ToString()); + GlobalWinF.MainForm.LoadState("QuickSave" + slot.ToString(), true); } - catch - { - return; - } - - if (x < 0 || x > 9) - return; - - GlobalWinF.MainForm.LoadState("QuickSave" + x.ToString(), true); - } - - public string savestate_registerload(LuaFunction luaf, object name) - { - NamedLuaFunction nlf = new NamedLuaFunction(luaf, "OnSavestateLoad", name != null ? name.ToString() : null); - lua_functions.Add(nlf); - return nlf.GUID.ToString(); - } - - public string savestate_registersave(LuaFunction luaf, object name) - { - NamedLuaFunction nlf = new NamedLuaFunction(luaf, "OnSavestateSave", name != null ? name.ToString() : null); - lua_functions.Add(nlf); - return nlf.GUID.ToString(); } public void savestate_save(object lua_input) @@ -58,21 +50,12 @@ namespace BizHawk.MultiClient public void savestate_saveslot(object lua_input) { - int x; + int slot = LuaInt(lua_input); - try //adelikat: This crap might not be necessary, need to test for a more elegant solution + if (slot >= 0 && slot <= 9) { - x = int.Parse(lua_input.ToString()); + GlobalWinF.MainForm.SaveState("QuickSave" + slot.ToString()); } - catch - { - return; - } - - if (x < 0 || x > 9) - return; - - GlobalWinF.MainForm.SaveState("QuickSave" + x.ToString()); } } } diff --git a/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.cs b/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.cs index 5ba58b06b1..4fdeb32c0e 100644 --- a/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.cs +++ b/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.cs @@ -61,7 +61,7 @@ namespace BizHawk.MultiClient "frameskip", "getsystemid", "islagged", - "ispaused", + "ispaused", "lagcount", "limitframerate", "minimizeframeskip", @@ -106,16 +106,6 @@ namespace BizHawk.MultiClient "textbox", }; - public static string[] SaveStateFunctions = new[] - { - "load", - "loadslot", - "registerload", - "registersave", - "save", - "saveslot", - }; - public void LuaRegister(Lua lua) { lua.RegisterFunction("print", this, GetType().GetMethod("print")); @@ -129,6 +119,7 @@ namespace BizHawk.MultiClient new MainMemoryLuaLibrary(_lua).LuaRegister(lua, Docs); new MovieLuaLibrary(_lua).LuaRegister(lua, Docs); new NESLuaLibrary().LuaRegister(lua, Docs); + new SavestateLuaLibrary().LuaRegister(lua, Docs); new SNESLuaLibrary().LuaRegister(lua, Docs); lua.NewTable("gui"); @@ -145,14 +136,6 @@ namespace BizHawk.MultiClient Docs.Add("emu", t, GetType().GetMethod("emu_" + t)); } - lua.NewTable("savestate"); - foreach (string t in SaveStateFunctions) - { - lua.RegisterFunction("savestate." + t, this, - GetType().GetMethod("savestate_" + t)); - Docs.Add("savestate", t, GetType().GetMethod("savestate_" + t)); - } - lua.NewTable("forms"); foreach (string t in FormsFunctions) {