From b65064eb139a1209b0cc57b3ad7932131cf70c86 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 12 Oct 2012 20:19:26 +0000 Subject: [PATCH] Lua - start an Event library and implement event.onloadstate(), event.onsavestate(), event.onframestart(), event.onframeend, event.oninputpoll(), All of these are aliases of other functions --- BizHawk.MultiClient/LuaImplementation.cs | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/BizHawk.MultiClient/LuaImplementation.cs b/BizHawk.MultiClient/LuaImplementation.cs index b535adb150..d8ad1f0812 100644 --- a/BizHawk.MultiClient/LuaImplementation.cs +++ b/BizHawk.MultiClient/LuaImplementation.cs @@ -212,6 +212,13 @@ namespace BizHawk.MultiClient docs.Add("nes", NESFunctions[i], this.GetType().GetMethod("nes_" + NESFunctions[i])); } + lua.NewTable("event"); + for (int i = 0; i < EventFunctions.Length; i++) + { + lua.RegisterFunction("event." + EventFunctions[i], this, this.GetType().GetMethod("event_" + EventFunctions[i])); + docs.Add("event", EventFunctions[i], this.GetType().GetMethod("event_" + EventFunctions[i])); + } + docs.Sort(); } @@ -556,6 +563,17 @@ namespace BizHawk.MultiClient "addgamegenie", "removegamegenie", }; + + public static string[] EventFunctions = new string[] + { + "onloadstate", + "onsavestate", + "onframestart", + "onframeend", + //"onmemoryread", + //"onmemorywrite", + "oninputpoll", + }; /****************************************************/ /*************function definitions********************/ /****************************************************/ @@ -2652,5 +2670,30 @@ namespace BizHawk.MultiClient } } } + + public void event_onsavestate(LuaFunction luaf) + { + savestate_registersave(luaf); + } + + public void event_onloadstate(LuaFunction luaf) + { + savestate_registerload(luaf); + } + + public void event_onframestart(LuaFunction luaf) + { + emu_registerbefore(luaf); + } + + public void event_onframeend(LuaFunction luaf) + { + emu_registerafter(luaf); + } + + public void event_oninputpoll(LuaFunction luaf) + { + emu_on_snoop(luaf); + } } }