Update Lua libs' ApiContainer when updating services

I don't think this mattered unless the tool restart was triggered by reloading
the rom with client.reboot_core(), which in my defence has always been jank
This commit is contained in:
YoshiRulz 2020-12-06 05:39:15 +10:00
parent febd4f1340
commit cf901753ba
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 18 additions and 6 deletions

View File

@ -21,7 +21,7 @@ namespace BizHawk.Client.Common
public abstract string Name { get; }
protected readonly ApiContainer APIs;
public ApiContainer APIs { protected get; set; }
protected readonly Action<string> LogOutputCallback;

View File

@ -217,7 +217,7 @@ namespace BizHawk.Client.EmuHawk
if (luaLibsImpl.IsRebootingCore)
{
// Even if the lua console is self-rebooting from client.reboot_core() we still want to re-inject dependencies
luaLibsImpl.Restart(Emulator.ServiceProvider);
luaLibsImpl.Restart(Emulator.ServiceProvider, Config, Emulator, Game);
return;
}

View File

@ -43,10 +43,12 @@ namespace BizHawk.Client.EmuHawk
if (true /*NLua.Lua.WhichLua == "NLua"*/) _lua["keepalives"] = _lua.NewTable();
_th = new NLuaTableHelper(_lua);
_displayManager = displayManager;
_inputManager = inputManager;
_mainForm = mainForm;
LuaWait = new AutoResetEvent(false);
Docs.Clear();
var apiContainer = ApiManager.RestartLua(serviceProvider, LogToLuaConsole, _mainForm, displayManager, inputManager, _mainForm.MovieSession, _mainForm.Tools, config, emulator, game);
var apiContainer = ApiManager.RestartLua(serviceProvider, LogToLuaConsole, _mainForm, _displayManager, _inputManager, _mainForm.MovieSession, _mainForm.Tools, config, emulator, game);
// Register lua libraries
foreach (var lib in Client.Common.ReflectionCache.Types.Concat(EmuHawk.ReflectionCache.Types)
@ -102,6 +104,10 @@ namespace BizHawk.Client.EmuHawk
EnumerateLuaFunctions(nameof(LuaCanvas), typeof(LuaCanvas), null); // add LuaCanvas to Lua function reference table
}
private readonly DisplayManager _displayManager;
private readonly InputManager _inputManager;
private readonly MainForm _mainForm;
private Lua _lua = new Lua();
@ -135,11 +141,17 @@ namespace BizHawk.Client.EmuHawk
public NLuaTableHelper GetTableHelper() => _th;
public void Restart(IEmulatorServiceProvider newServiceProvider)
public void Restart(
IEmulatorServiceProvider newServiceProvider,
Config config,
IEmulator emulator,
IGameInfo game)
{
foreach (var lib in Libraries)
var apiContainer = ApiManager.RestartLua(newServiceProvider, LogToLuaConsole, _mainForm, _displayManager, _inputManager, _mainForm.MovieSession, _mainForm.Tools, config, emulator, game);
foreach (var lib in Libraries.Values)
{
ServiceInjector.UpdateServices(newServiceProvider, lib.Value);
lib.APIs = apiContainer;
ServiceInjector.UpdateServices(newServiceProvider, lib);
}
}