Lua - implement event.onexit() - fires when the calling script stops execution, supports multiple callbacks per script
This commit is contained in:
parent
299c27ae6e
commit
0782c9820d
|
@ -21,6 +21,15 @@ namespace BizHawk.Client.Common
|
|||
|
||||
#region Events Library Helpers
|
||||
|
||||
public void CallExitEvent(Lua thread)
|
||||
{
|
||||
var exitCallbacks = _luaFunctions.Where(x => x.Lua == thread && x.Event == "OnExit");
|
||||
foreach (var exitCallback in exitCallbacks)
|
||||
{
|
||||
exitCallback.Call();
|
||||
}
|
||||
}
|
||||
|
||||
public LuaFunctionList RegisteredFunctions { get { return _luaFunctions; } }
|
||||
|
||||
public void CallSaveStateEvent(string name)
|
||||
|
@ -204,6 +213,17 @@ namespace BizHawk.Client.Common
|
|||
return nlf.Guid.ToString();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"onexit",
|
||||
"Fires after the calling script has stopped"
|
||||
)]
|
||||
public string OnExit(LuaFunction luaf, string name = null)
|
||||
{
|
||||
var nlf = new NamedLuaFunction(luaf, "OnExit", LogOutputCallback, CurrentThread, name);
|
||||
_luaFunctions.Add(nlf);
|
||||
return nlf.Guid.ToString();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"unregisterbyid",
|
||||
"Removes the registered function that matches the guid. If a function is found and remove the function will return true. If unable to find a match, the function will return false."
|
||||
|
|
|
@ -111,6 +111,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
_eventLibrary.CallFrameAfterEvent();
|
||||
}
|
||||
|
||||
public void CallExitEvent(Lua thread)
|
||||
{
|
||||
_eventLibrary.CallExitEvent(thread);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
_lua = new Lua();
|
||||
|
|
|
@ -389,6 +389,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var result = LuaImp.ResumeScript(lf.Thread);
|
||||
if (result.Terminated)
|
||||
{
|
||||
LuaImp.CallExitEvent(lf.Thread);
|
||||
lf.Stop();
|
||||
}
|
||||
|
||||
|
@ -717,6 +718,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
else if (!item.Enabled && item.Thread != null)
|
||||
{
|
||||
LuaImp.CallExitEvent(item.Thread);
|
||||
|
||||
var items = SelectedItems.ToList();
|
||||
foreach (var sitem in items)
|
||||
{
|
||||
|
@ -730,6 +733,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
UpdateRegisteredFunctionsDialog();
|
||||
}
|
||||
|
||||
LuaImp.CallExitEvent(item.Thread);
|
||||
item.Stop();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue