Add event.onconsoleclose (squashed PR #2884)

This commit is contained in:
Hyago Oliveira 2021-07-29 19:44:24 -03:00 committed by GitHub
parent 0f294a220e
commit dc66b4357f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -232,6 +232,12 @@ namespace BizHawk.Client.Common
=> _luaLibsImpl.CreateAndRegisterNamedFunction(luaf, "OnExit", LogOutputCallback, CurrentFile, name)
.Guid.ToString();
[LuaMethodExample("local closeGuid = event.onconsoleclose(\r\n\tfunction()\r\n\t\tconsole.log( \"Fires when the emulator console closes\" );\r\n\tend\r\n\t, \"Frame name\" );")]
[LuaMethod("onconsoleclose", "Fires when the emulator console closes")]
public string OnConsoleClose(LuaFunction luaf, string name = null)
=> _luaLibsImpl.CreateAndRegisterNamedFunction(luaf, "OnConsoleClose", LogOutputCallback, CurrentFile, name)
.Guid.ToString();
[LuaMethodExample("if ( event.unregisterbyid( \"4d1810b7 - 0d28 - 4acb - 9d8b - d87721641551\" ) ) then\r\n\tconsole.log( \"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.\" );\r\nend;")]
[LuaMethod("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.")]
public bool UnregisterById(string guid) => _luaLibsImpl.RemoveNamedFunctionMatching(nlf => nlf.Guid.ToString() == guid);

View File

@ -247,6 +247,12 @@ namespace BizHawk.Client.EmuHawk
public void Close()
{
foreach (var closeCallback in RegisteredFunctions
.Where(l => l.Event == "OnConsoleClose"))
{
closeCallback.Call();
}
RegisteredFunctions.Clear(_mainForm.Emulator);
ScriptList.Clear();
FormsLibrary.DestroyAll();