move event library to its own object, slight tweak to anonymous function name, double clicking on registered functions dialog invokes the method clicked
This commit is contained in:
parent
092b87e267
commit
d7d83c9275
|
@ -12,7 +12,7 @@ namespace BizHawk.Client.Common
|
||||||
public NamedLuaFunction(LuaFunction function, string theevent, string name = null)
|
public NamedLuaFunction(LuaFunction function, string theevent, string name = null)
|
||||||
{
|
{
|
||||||
_function = function;
|
_function = function;
|
||||||
_name = name ?? "Anonymous Function";
|
_name = name ?? "Anonymous";
|
||||||
_event = theevent;
|
_event = theevent;
|
||||||
GUID = Guid.NewGuid();
|
GUID = Guid.NewGuid();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2351,7 +2351,7 @@ namespace BizHawk.MultiClient
|
||||||
if (_luaconsole != null)
|
if (_luaconsole != null)
|
||||||
{
|
{
|
||||||
if (!fromLua) LuaConsole1.StartLuaDrawing();
|
if (!fromLua) LuaConsole1.StartLuaDrawing();
|
||||||
LuaConsole1.LuaImp.FrameRegisterBefore();
|
LuaConsole1.LuaImp.CallFrameBeforeEvent();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (_nesnametableview != null) NESNameTableViewer1.UpdateValues();
|
if (_nesnametableview != null) NESNameTableViewer1.UpdateValues();
|
||||||
|
@ -2392,7 +2392,7 @@ namespace BizHawk.MultiClient
|
||||||
#if WINDOWS
|
#if WINDOWS
|
||||||
if (_luaconsole != null)
|
if (_luaconsole != null)
|
||||||
{
|
{
|
||||||
LuaConsole1.LuaImp.FrameRegisterAfter();
|
LuaConsole1.LuaImp.CallFrameAfterEvent();
|
||||||
if (!fromLua)
|
if (!fromLua)
|
||||||
{
|
{
|
||||||
GlobalWinF.DisplayManager.PreFrameUpdateLuaSource();
|
GlobalWinF.DisplayManager.PreFrameUpdateLuaSource();
|
||||||
|
@ -2492,7 +2492,7 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveStateFile(path, name, false);
|
SaveStateFile(path, name, false);
|
||||||
LuaConsole1.LuaImp.SavestateRegisterSave(name);
|
LuaConsole1.LuaImp.CallSaveStateEvent(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveStateFile(string filename, string name, bool fromLua)
|
public void SaveStateFile(string filename, string name, bool fromLua)
|
||||||
|
@ -2672,7 +2672,7 @@ namespace BizHawk.MultiClient
|
||||||
UpdateToolsAfter(fromLua);
|
UpdateToolsAfter(fromLua);
|
||||||
UpdateToolsLoadstate();
|
UpdateToolsLoadstate();
|
||||||
GlobalWinF.OSD.AddMessage("Loaded state: " + name);
|
GlobalWinF.OSD.AddMessage("Loaded state: " + name);
|
||||||
LuaConsole1.LuaImp.SavestateRegisterLoad(name);
|
LuaConsole1.LuaImp.CallLoadStateEvent(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadState(string name, bool fromLua = false)
|
public void LoadState(string name, bool fromLua = false)
|
||||||
|
|
|
@ -6,15 +6,35 @@ using BizHawk.Client.Common;
|
||||||
|
|
||||||
namespace BizHawk.MultiClient
|
namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
public partial class EmuLuaLibrary
|
public class EventLuaLibrary : LuaLibraryBase
|
||||||
{
|
{
|
||||||
|
public override string Name { get { return "event"; } }
|
||||||
|
public override string[] Functions
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new[]
|
||||||
|
{
|
||||||
|
"onframeend",
|
||||||
|
"onframestart",
|
||||||
|
"oninputpoll",
|
||||||
|
"onloadstate",
|
||||||
|
"onmemoryread",
|
||||||
|
"onmemorywrite",
|
||||||
|
"onsavestate",
|
||||||
|
"unregisterbyid",
|
||||||
|
"unregisterbyname",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region Events Library Helpers
|
#region Events Library Helpers
|
||||||
|
|
||||||
private readonly LuaFunctionList lua_functions = new LuaFunctionList();
|
private readonly LuaFunctionList lua_functions = new LuaFunctionList();
|
||||||
|
|
||||||
public LuaFunctionList RegisteredFunctions { get { return lua_functions; } }
|
public LuaFunctionList RegisteredFunctions { get { return lua_functions; } }
|
||||||
|
|
||||||
public void SavestateRegisterSave(string name)
|
public void CallSaveStateEvent(string name)
|
||||||
{
|
{
|
||||||
List<NamedLuaFunction> lfs = lua_functions.Where(x => x.Event == "OnSavestateSave").ToList();
|
List<NamedLuaFunction> lfs = lua_functions.Where(x => x.Event == "OnSavestateSave").ToList();
|
||||||
if (lfs.Any())
|
if (lfs.Any())
|
||||||
|
@ -35,7 +55,7 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SavestateRegisterLoad(string name)
|
public void CallLoadStateEvent(string name)
|
||||||
{
|
{
|
||||||
List<NamedLuaFunction> lfs = lua_functions.Where(x => x.Event == "OnSavestateLoad").ToList();
|
List<NamedLuaFunction> lfs = lua_functions.Where(x => x.Event == "OnSavestateLoad").ToList();
|
||||||
if (lfs.Any())
|
if (lfs.Any())
|
||||||
|
@ -56,7 +76,7 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FrameRegisterBefore()
|
public void CallFrameBeforeEvent()
|
||||||
{
|
{
|
||||||
List<NamedLuaFunction> lfs = lua_functions.Where(x => x.Event == "OnFrameStart").ToList();
|
List<NamedLuaFunction> lfs = lua_functions.Where(x => x.Event == "OnFrameStart").ToList();
|
||||||
if (lfs.Any())
|
if (lfs.Any())
|
||||||
|
@ -77,7 +97,7 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FrameRegisterAfter()
|
public void CallFrameAfterEvent()
|
||||||
{
|
{
|
||||||
List<NamedLuaFunction> lfs = lua_functions.Where(x => x.Event == "OnFrameEnd").ToList();
|
List<NamedLuaFunction> lfs = lua_functions.Where(x => x.Event == "OnFrameEnd").ToList();
|
||||||
if (lfs.Any())
|
if (lfs.Any())
|
||||||
|
@ -116,7 +136,26 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
public void event_oninputpoll(LuaFunction luaf)
|
public void event_oninputpoll(LuaFunction luaf)
|
||||||
{
|
{
|
||||||
emu_on_snoop(luaf);
|
if (luaf != null)
|
||||||
|
{
|
||||||
|
Global.Emulator.CoreComm.InputCallback = delegate
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
luaf.Call();
|
||||||
|
}
|
||||||
|
catch (SystemException e)
|
||||||
|
{
|
||||||
|
GlobalWinF.MainForm.LuaConsole1.WriteToOutputWindow(
|
||||||
|
"error running function attached by lua function emu.on_snoop" +
|
||||||
|
"\nError message: " + e.Message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Global.Emulator.CoreComm.InputCallback = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string event_onloadstate(LuaFunction luaf, object name = null)
|
public string event_onloadstate(LuaFunction luaf, object name = null)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
using LuaInterface;
|
using LuaInterface;
|
||||||
|
using BizHawk.Client.Common;
|
||||||
|
|
||||||
namespace BizHawk.MultiClient
|
namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
|
@ -10,6 +12,7 @@ namespace BizHawk.MultiClient
|
||||||
private readonly LuaConsole _caller;
|
private readonly LuaConsole _caller;
|
||||||
private Lua currThread;
|
private Lua currThread;
|
||||||
private FormsLuaLibrary _formsLibrary = new FormsLuaLibrary();
|
private FormsLuaLibrary _formsLibrary = new FormsLuaLibrary();
|
||||||
|
private EventLuaLibrary _eventLibrary = new EventLuaLibrary();
|
||||||
|
|
||||||
public LuaDocumentation Docs = new LuaDocumentation();
|
public LuaDocumentation Docs = new LuaDocumentation();
|
||||||
public bool IsRunning;
|
public bool IsRunning;
|
||||||
|
@ -21,6 +24,31 @@ namespace BizHawk.MultiClient
|
||||||
_formsLibrary.WindowClosed(handle);
|
_formsLibrary.WindowClosed(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CallSaveStateEvent(string name)
|
||||||
|
{
|
||||||
|
_eventLibrary.CallSaveStateEvent(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CallLoadStateEvent(string name)
|
||||||
|
{
|
||||||
|
_eventLibrary.CallLoadStateEvent(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LuaFunctionList RegisteredFunctions
|
||||||
|
{
|
||||||
|
get { return _eventLibrary.RegisteredFunctions; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CallFrameBeforeEvent()
|
||||||
|
{
|
||||||
|
_eventLibrary.CallFrameBeforeEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CallFrameAfterEvent()
|
||||||
|
{
|
||||||
|
_eventLibrary.CallFrameAfterEvent();
|
||||||
|
}
|
||||||
|
|
||||||
public EmuLuaLibrary(LuaConsole passed)
|
public EmuLuaLibrary(LuaConsole passed)
|
||||||
{
|
{
|
||||||
LuaWait = new AutoResetEvent(false);
|
LuaWait = new AutoResetEvent(false);
|
||||||
|
@ -80,19 +108,6 @@ namespace BizHawk.MultiClient
|
||||||
"yield",
|
"yield",
|
||||||
};
|
};
|
||||||
|
|
||||||
public static string[] EventFunctions = new[]
|
|
||||||
{
|
|
||||||
"onframeend",
|
|
||||||
"onframestart",
|
|
||||||
"oninputpoll",
|
|
||||||
"onloadstate",
|
|
||||||
"onmemoryread",
|
|
||||||
"onmemorywrite",
|
|
||||||
"onsavestate",
|
|
||||||
"unregisterbyid",
|
|
||||||
"unregisterbyname",
|
|
||||||
};
|
|
||||||
|
|
||||||
public void LuaRegister(Lua lua)
|
public void LuaRegister(Lua lua)
|
||||||
{
|
{
|
||||||
lua.RegisterFunction("print", this, GetType().GetMethod("print"));
|
lua.RegisterFunction("print", this, GetType().GetMethod("print"));
|
||||||
|
@ -100,6 +115,7 @@ namespace BizHawk.MultiClient
|
||||||
new BitLuaLibrary().LuaRegister(lua, Docs);
|
new BitLuaLibrary().LuaRegister(lua, Docs);
|
||||||
new MultiClientLuaLibrary(ConsoleLuaLibrary.console_log).LuaRegister(lua, Docs);
|
new MultiClientLuaLibrary(ConsoleLuaLibrary.console_log).LuaRegister(lua, Docs);
|
||||||
new ConsoleLuaLibrary().LuaRegister(lua, Docs);
|
new ConsoleLuaLibrary().LuaRegister(lua, Docs);
|
||||||
|
_eventLibrary.LuaRegister(lua, Docs);
|
||||||
_formsLibrary.LuaRegister(lua, Docs);
|
_formsLibrary.LuaRegister(lua, Docs);
|
||||||
new InputLuaLibrary(_lua).LuaRegister(lua, Docs);
|
new InputLuaLibrary(_lua).LuaRegister(lua, Docs);
|
||||||
new JoypadLuaLibrary(_lua).LuaRegister(lua, Docs);
|
new JoypadLuaLibrary(_lua).LuaRegister(lua, Docs);
|
||||||
|
@ -124,13 +140,6 @@ namespace BizHawk.MultiClient
|
||||||
Docs.Add("emu", t, GetType().GetMethod("emu_" + t));
|
Docs.Add("emu", t, GetType().GetMethod("emu_" + t));
|
||||||
}
|
}
|
||||||
|
|
||||||
lua.NewTable("event");
|
|
||||||
foreach (string t in EventFunctions)
|
|
||||||
{
|
|
||||||
lua.RegisterFunction("event." + t, this, GetType().GetMethod("event_" + t));
|
|
||||||
Docs.Add("event", t, GetType().GetMethod("event_" + t));
|
|
||||||
}
|
|
||||||
|
|
||||||
Docs.Sort();
|
Docs.Sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,7 @@
|
||||||
this.FunctionView.UseCompatibleStateImageBehavior = false;
|
this.FunctionView.UseCompatibleStateImageBehavior = false;
|
||||||
this.FunctionView.View = System.Windows.Forms.View.Details;
|
this.FunctionView.View = System.Windows.Forms.View.Details;
|
||||||
this.FunctionView.SelectedIndexChanged += new System.EventHandler(this.FunctionView_SelectedIndexChanged);
|
this.FunctionView.SelectedIndexChanged += new System.EventHandler(this.FunctionView_SelectedIndexChanged);
|
||||||
|
this.FunctionView.DoubleClick += new System.EventHandler(this.FunctionView_DoubleClick);
|
||||||
//
|
//
|
||||||
// FunctionsEvent
|
// FunctionsEvent
|
||||||
//
|
//
|
||||||
|
|
|
@ -78,5 +78,10 @@ namespace BizHawk.MultiClient
|
||||||
CallButton.Enabled = indexes.Count > 0;
|
CallButton.Enabled = indexes.Count > 0;
|
||||||
RemoveButton.Enabled = indexes.Count > 0;
|
RemoveButton.Enabled = indexes.Count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void FunctionView_DoubleClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CallFunction();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue