BizHawk/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs

267 lines
7.3 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using NLua;
using BizHawk.Common.ReflectionExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
Add preliminary Unix compatibility (using Mono; resolves #1384) (#1380) * Move PlatformSpecificLinkedLibs and implementations to common and rename * Specify file ext. at LoadPlatformSpecific call site * Move Client.Common.Global.RunningOnUnix to PlatformLinkedLibSingleton * Inline var Resolver * Use PlatformLinkedLibManager internally * Move plugin load check to LinkedLibManager, use LinkedLibManager * Interpolate * Return exit code from dlclose/FreeLibrary * Skip all calls to externs in BlipBufDll when using mono * Use PlatformLinkedLibManager in SevenZipLibraryManager * Add expected return value to workaround (from testing on Win32) * Remove ".dll" from DllImport attr, remove temporary workaround, see desc. The library can be built by changing the output file name in `.../blip_buf/Makefile` to `libblip_buf.so`, and running `make`. It will be loaded if placed in the `.../output` folder. * Remove unused code, add TODO (this class is req. for Waterbox.PeWrapper) The TODO is to [rewrite with C#](https://docs.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files) instead of importing from `kernel32.dll`. * Update OpenTK again but better (for #1384) * Add Mono run script * Add libblip_buf.so (temporary) Temporary because it should be a separate package which BizHawk depends on. * Add distro detection, add "already running" and "unknown distro" messages * Gray-out Lua Console on Unix * Extract superclass from EmuLuaLibrary, add shell implementation for Unix * Specify libdl version, Fedora doesn't have the versionless symlink * Remove empty `ToolStripMenuItem`, null `Text` caused crash on Unix * Transform OpenTK keyboard input into a `List<KeyEvent>` and read that Also fixes crash on rebind * Remove debug `using ...;`
2019-01-03 22:50:55 +00:00
public class EmuLuaLibrary : PlatformEmuLuaLibrary
{
private readonly MainForm _mainForm;
public EmuLuaLibrary()
{
// if (NLua.Lua.WhichLua == "NLua")
_lua["keepalives"] = _lua.NewTable();
}
public EmuLuaLibrary(IEmulatorServiceProvider serviceProvider, MainForm mainForm)
: this()
2014-01-21 16:31:12 +00:00
{
_mainForm = mainForm;
static ApiContainer InitApiHawkContainerInstance(IEmulatorServiceProvider sp, Action<string> logCallback)
{
var ctorParamTypes = new[] { typeof(Action<string>) };
var ctorParams = new object[] { logCallback };
var libDict = new Dictionary<Type, IExternalApi>();
foreach (var api in Assembly.GetAssembly(typeof(EmuApi)).GetTypes()
.Concat(Assembly.GetAssembly(typeof(ToolApi)).GetTypes())
.Where(t => t.IsSealed && typeof(IExternalApi).IsAssignableFrom(t) && ServiceInjector.IsAvailable(sp, t)))
{
var ctorWithParams = api.GetConstructor(ctorParamTypes);
var instance = (IExternalApi) (ctorWithParams == null ? Activator.CreateInstance(api) : ctorWithParams.Invoke(ctorParams));
ServiceInjector.UpdateServices(sp, instance);
libDict.Add(api, instance);
}
return ApiHawkContainerInstance = new ApiContainer(libDict);
}
2014-01-21 16:31:12 +00:00
LuaWait = new AutoResetEvent(false);
Docs.Clear();
// Register lua libraries
2019-12-15 18:08:10 +00:00
foreach (var lib in Assembly.Load("BizHawk.Client.Common").GetTypes()
.Concat(Assembly.GetAssembly(typeof(EmuLuaLibrary)).GetTypes())
.Where(t => typeof(LuaLibraryBase).IsAssignableFrom(t) && t.IsSealed && ServiceInjector.IsAvailable(serviceProvider, t)))
{
bool addLibrary = true;
var attributes = lib.GetCustomAttributes(typeof(LuaLibraryAttribute), false);
if (attributes.Any())
{
2019-11-29 19:14:30 +00:00
addLibrary = VersionInfo.DeveloperBuild || ((LuaLibraryAttribute)attributes.First()).Released;
}
if (addLibrary)
{
var instance = (LuaLibraryBase)Activator.CreateInstance(lib, _lua);
instance.LuaRegister(lib, Docs);
instance.LogOutputCallback = ConsoleLuaLibrary.LogOutput;
ServiceInjector.UpdateServices(serviceProvider, instance);
// TODO: make EmuHawk libraries have a base class with common properties such as this
// and inject them here
if (instance is EmuHawkLuaLibrary emuHawkLibrary)
{
emuHawkLibrary.MainForm = _mainForm;
}
ApiHawkContainerInstance = InitApiHawkContainerInstance(serviceProvider, ConsoleLuaLibrary.LogOutput);
if (instance is DelegatingLuaLibraryEmu dlgInstanceEmu) dlgInstanceEmu.APIs = ApiHawkContainerInstance; // this is necessary as the property has the `new` modifier
else if (instance is DelegatingLuaLibrary dlgInstance) dlgInstance.APIs = ApiHawkContainerInstance;
Libraries.Add(lib, instance);
}
}
_lua.RegisterFunction("print", this, GetType().GetMethod("Print"));
EmulatorLuaLibrary.FrameAdvanceCallback = Frameadvance;
EmulatorLuaLibrary.YieldCallback = EmuYield;
// Add LuaCanvas to Docs
Type luaCanvas = typeof(LuaCanvas);
2019-12-15 18:08:10 +00:00
foreach (var method in luaCanvas.GetMethods())
{
2019-12-15 18:08:10 +00:00
if (method.GetCustomAttributes(typeof(LuaMethodAttribute), false).Length != 0)
{
Docs.Add(new LibraryFunction(nameof(LuaCanvas), luaCanvas.Description(), method));
}
}
2014-01-21 16:31:12 +00:00
}
/// <remarks>lazily instantiated</remarks>
private static ApiContainer ApiHawkContainerInstance;
private Lua _lua = new Lua();
private Lua _currThread;
private FormsLuaLibrary FormsLibrary => (FormsLuaLibrary)Libraries[typeof(FormsLuaLibrary)];
private EventLuaLibrary EventsLibrary => (EventLuaLibrary)Libraries[typeof(EventLuaLibrary)];
private EmulatorLuaLibrary EmulatorLuaLibrary => (EmulatorLuaLibrary)Libraries[typeof(EmulatorLuaLibrary)];
Add preliminary Unix compatibility (using Mono; resolves #1384) (#1380) * Move PlatformSpecificLinkedLibs and implementations to common and rename * Specify file ext. at LoadPlatformSpecific call site * Move Client.Common.Global.RunningOnUnix to PlatformLinkedLibSingleton * Inline var Resolver * Use PlatformLinkedLibManager internally * Move plugin load check to LinkedLibManager, use LinkedLibManager * Interpolate * Return exit code from dlclose/FreeLibrary * Skip all calls to externs in BlipBufDll when using mono * Use PlatformLinkedLibManager in SevenZipLibraryManager * Add expected return value to workaround (from testing on Win32) * Remove ".dll" from DllImport attr, remove temporary workaround, see desc. The library can be built by changing the output file name in `.../blip_buf/Makefile` to `libblip_buf.so`, and running `make`. It will be loaded if placed in the `.../output` folder. * Remove unused code, add TODO (this class is req. for Waterbox.PeWrapper) The TODO is to [rewrite with C#](https://docs.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files) instead of importing from `kernel32.dll`. * Update OpenTK again but better (for #1384) * Add Mono run script * Add libblip_buf.so (temporary) Temporary because it should be a separate package which BizHawk depends on. * Add distro detection, add "already running" and "unknown distro" messages * Gray-out Lua Console on Unix * Extract superclass from EmuLuaLibrary, add shell implementation for Unix * Specify libdl version, Fedora doesn't have the versionless symlink * Remove empty `ToolStripMenuItem`, null `Text` caused crash on Unix * Transform OpenTK keyboard input into a `List<KeyEvent>` and read that Also fixes crash on rebind * Remove debug `using ...;`
2019-01-03 22:50:55 +00:00
public override void Restart(IEmulatorServiceProvider newServiceProvider)
{
foreach (var lib in Libraries)
{
ServiceInjector.UpdateServices(newServiceProvider, lib.Value);
}
}
Add preliminary Unix compatibility (using Mono; resolves #1384) (#1380) * Move PlatformSpecificLinkedLibs and implementations to common and rename * Specify file ext. at LoadPlatformSpecific call site * Move Client.Common.Global.RunningOnUnix to PlatformLinkedLibSingleton * Inline var Resolver * Use PlatformLinkedLibManager internally * Move plugin load check to LinkedLibManager, use LinkedLibManager * Interpolate * Return exit code from dlclose/FreeLibrary * Skip all calls to externs in BlipBufDll when using mono * Use PlatformLinkedLibManager in SevenZipLibraryManager * Add expected return value to workaround (from testing on Win32) * Remove ".dll" from DllImport attr, remove temporary workaround, see desc. The library can be built by changing the output file name in `.../blip_buf/Makefile` to `libblip_buf.so`, and running `make`. It will be loaded if placed in the `.../output` folder. * Remove unused code, add TODO (this class is req. for Waterbox.PeWrapper) The TODO is to [rewrite with C#](https://docs.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files) instead of importing from `kernel32.dll`. * Update OpenTK again but better (for #1384) * Add Mono run script * Add libblip_buf.so (temporary) Temporary because it should be a separate package which BizHawk depends on. * Add distro detection, add "already running" and "unknown distro" messages * Gray-out Lua Console on Unix * Extract superclass from EmuLuaLibrary, add shell implementation for Unix * Specify libdl version, Fedora doesn't have the versionless symlink * Remove empty `ToolStripMenuItem`, null `Text` caused crash on Unix * Transform OpenTK keyboard input into a `List<KeyEvent>` and read that Also fixes crash on rebind * Remove debug `using ...;`
2019-01-03 22:50:55 +00:00
public override void StartLuaDrawing()
{
2019-12-15 18:08:10 +00:00
if (ScriptList.Count != 0 && GuiLibrary.SurfaceIsNull)
{
GuiLibrary.DrawNew("emu");
}
}
Add preliminary Unix compatibility (using Mono; resolves #1384) (#1380) * Move PlatformSpecificLinkedLibs and implementations to common and rename * Specify file ext. at LoadPlatformSpecific call site * Move Client.Common.Global.RunningOnUnix to PlatformLinkedLibSingleton * Inline var Resolver * Use PlatformLinkedLibManager internally * Move plugin load check to LinkedLibManager, use LinkedLibManager * Interpolate * Return exit code from dlclose/FreeLibrary * Skip all calls to externs in BlipBufDll when using mono * Use PlatformLinkedLibManager in SevenZipLibraryManager * Add expected return value to workaround (from testing on Win32) * Remove ".dll" from DllImport attr, remove temporary workaround, see desc. The library can be built by changing the output file name in `.../blip_buf/Makefile` to `libblip_buf.so`, and running `make`. It will be loaded if placed in the `.../output` folder. * Remove unused code, add TODO (this class is req. for Waterbox.PeWrapper) The TODO is to [rewrite with C#](https://docs.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files) instead of importing from `kernel32.dll`. * Update OpenTK again but better (for #1384) * Add Mono run script * Add libblip_buf.so (temporary) Temporary because it should be a separate package which BizHawk depends on. * Add distro detection, add "already running" and "unknown distro" messages * Gray-out Lua Console on Unix * Extract superclass from EmuLuaLibrary, add shell implementation for Unix * Specify libdl version, Fedora doesn't have the versionless symlink * Remove empty `ToolStripMenuItem`, null `Text` caused crash on Unix * Transform OpenTK keyboard input into a `List<KeyEvent>` and read that Also fixes crash on rebind * Remove debug `using ...;`
2019-01-03 22:50:55 +00:00
public override void EndLuaDrawing()
{
2019-12-15 18:08:10 +00:00
if (ScriptList.Count != 0)
{
GuiLibrary.DrawFinish();
}
}
public bool FrameAdvanceRequested { get; private set; }
public override LuaFunctionList RegisteredFunctions => EventsLibrary.RegisteredFunctions;
Add preliminary Unix compatibility (using Mono; resolves #1384) (#1380) * Move PlatformSpecificLinkedLibs and implementations to common and rename * Specify file ext. at LoadPlatformSpecific call site * Move Client.Common.Global.RunningOnUnix to PlatformLinkedLibSingleton * Inline var Resolver * Use PlatformLinkedLibManager internally * Move plugin load check to LinkedLibManager, use LinkedLibManager * Interpolate * Return exit code from dlclose/FreeLibrary * Skip all calls to externs in BlipBufDll when using mono * Use PlatformLinkedLibManager in SevenZipLibraryManager * Add expected return value to workaround (from testing on Win32) * Remove ".dll" from DllImport attr, remove temporary workaround, see desc. The library can be built by changing the output file name in `.../blip_buf/Makefile` to `libblip_buf.so`, and running `make`. It will be loaded if placed in the `.../output` folder. * Remove unused code, add TODO (this class is req. for Waterbox.PeWrapper) The TODO is to [rewrite with C#](https://docs.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files) instead of importing from `kernel32.dll`. * Update OpenTK again but better (for #1384) * Add Mono run script * Add libblip_buf.so (temporary) Temporary because it should be a separate package which BizHawk depends on. * Add distro detection, add "already running" and "unknown distro" messages * Gray-out Lua Console on Unix * Extract superclass from EmuLuaLibrary, add shell implementation for Unix * Specify libdl version, Fedora doesn't have the versionless symlink * Remove empty `ToolStripMenuItem`, null `Text` caused crash on Unix * Transform OpenTK keyboard input into a `List<KeyEvent>` and read that Also fixes crash on rebind * Remove debug `using ...;`
2019-01-03 22:50:55 +00:00
public override void WindowClosed(IntPtr handle)
2013-10-31 16:45:08 +00:00
{
FormsLibrary.WindowClosed(handle);
2013-10-31 16:45:08 +00:00
}
Add preliminary Unix compatibility (using Mono; resolves #1384) (#1380) * Move PlatformSpecificLinkedLibs and implementations to common and rename * Specify file ext. at LoadPlatformSpecific call site * Move Client.Common.Global.RunningOnUnix to PlatformLinkedLibSingleton * Inline var Resolver * Use PlatformLinkedLibManager internally * Move plugin load check to LinkedLibManager, use LinkedLibManager * Interpolate * Return exit code from dlclose/FreeLibrary * Skip all calls to externs in BlipBufDll when using mono * Use PlatformLinkedLibManager in SevenZipLibraryManager * Add expected return value to workaround (from testing on Win32) * Remove ".dll" from DllImport attr, remove temporary workaround, see desc. The library can be built by changing the output file name in `.../blip_buf/Makefile` to `libblip_buf.so`, and running `make`. It will be loaded if placed in the `.../output` folder. * Remove unused code, add TODO (this class is req. for Waterbox.PeWrapper) The TODO is to [rewrite with C#](https://docs.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files) instead of importing from `kernel32.dll`. * Update OpenTK again but better (for #1384) * Add Mono run script * Add libblip_buf.so (temporary) Temporary because it should be a separate package which BizHawk depends on. * Add distro detection, add "already running" and "unknown distro" messages * Gray-out Lua Console on Unix * Extract superclass from EmuLuaLibrary, add shell implementation for Unix * Specify libdl version, Fedora doesn't have the versionless symlink * Remove empty `ToolStripMenuItem`, null `Text` caused crash on Unix * Transform OpenTK keyboard input into a `List<KeyEvent>` and read that Also fixes crash on rebind * Remove debug `using ...;`
2019-01-03 22:50:55 +00:00
public override void CallSaveStateEvent(string name)
{
EventsLibrary.CallSaveStateEvent(name);
}
Add preliminary Unix compatibility (using Mono; resolves #1384) (#1380) * Move PlatformSpecificLinkedLibs and implementations to common and rename * Specify file ext. at LoadPlatformSpecific call site * Move Client.Common.Global.RunningOnUnix to PlatformLinkedLibSingleton * Inline var Resolver * Use PlatformLinkedLibManager internally * Move plugin load check to LinkedLibManager, use LinkedLibManager * Interpolate * Return exit code from dlclose/FreeLibrary * Skip all calls to externs in BlipBufDll when using mono * Use PlatformLinkedLibManager in SevenZipLibraryManager * Add expected return value to workaround (from testing on Win32) * Remove ".dll" from DllImport attr, remove temporary workaround, see desc. The library can be built by changing the output file name in `.../blip_buf/Makefile` to `libblip_buf.so`, and running `make`. It will be loaded if placed in the `.../output` folder. * Remove unused code, add TODO (this class is req. for Waterbox.PeWrapper) The TODO is to [rewrite with C#](https://docs.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files) instead of importing from `kernel32.dll`. * Update OpenTK again but better (for #1384) * Add Mono run script * Add libblip_buf.so (temporary) Temporary because it should be a separate package which BizHawk depends on. * Add distro detection, add "already running" and "unknown distro" messages * Gray-out Lua Console on Unix * Extract superclass from EmuLuaLibrary, add shell implementation for Unix * Specify libdl version, Fedora doesn't have the versionless symlink * Remove empty `ToolStripMenuItem`, null `Text` caused crash on Unix * Transform OpenTK keyboard input into a `List<KeyEvent>` and read that Also fixes crash on rebind * Remove debug `using ...;`
2019-01-03 22:50:55 +00:00
public override void CallLoadStateEvent(string name)
{
EventsLibrary.CallLoadStateEvent(name);
}
Add preliminary Unix compatibility (using Mono; resolves #1384) (#1380) * Move PlatformSpecificLinkedLibs and implementations to common and rename * Specify file ext. at LoadPlatformSpecific call site * Move Client.Common.Global.RunningOnUnix to PlatformLinkedLibSingleton * Inline var Resolver * Use PlatformLinkedLibManager internally * Move plugin load check to LinkedLibManager, use LinkedLibManager * Interpolate * Return exit code from dlclose/FreeLibrary * Skip all calls to externs in BlipBufDll when using mono * Use PlatformLinkedLibManager in SevenZipLibraryManager * Add expected return value to workaround (from testing on Win32) * Remove ".dll" from DllImport attr, remove temporary workaround, see desc. The library can be built by changing the output file name in `.../blip_buf/Makefile` to `libblip_buf.so`, and running `make`. It will be loaded if placed in the `.../output` folder. * Remove unused code, add TODO (this class is req. for Waterbox.PeWrapper) The TODO is to [rewrite with C#](https://docs.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files) instead of importing from `kernel32.dll`. * Update OpenTK again but better (for #1384) * Add Mono run script * Add libblip_buf.so (temporary) Temporary because it should be a separate package which BizHawk depends on. * Add distro detection, add "already running" and "unknown distro" messages * Gray-out Lua Console on Unix * Extract superclass from EmuLuaLibrary, add shell implementation for Unix * Specify libdl version, Fedora doesn't have the versionless symlink * Remove empty `ToolStripMenuItem`, null `Text` caused crash on Unix * Transform OpenTK keyboard input into a `List<KeyEvent>` and read that Also fixes crash on rebind * Remove debug `using ...;`
2019-01-03 22:50:55 +00:00
public override void CallFrameBeforeEvent()
{
EventsLibrary.CallFrameBeforeEvent();
}
Add preliminary Unix compatibility (using Mono; resolves #1384) (#1380) * Move PlatformSpecificLinkedLibs and implementations to common and rename * Specify file ext. at LoadPlatformSpecific call site * Move Client.Common.Global.RunningOnUnix to PlatformLinkedLibSingleton * Inline var Resolver * Use PlatformLinkedLibManager internally * Move plugin load check to LinkedLibManager, use LinkedLibManager * Interpolate * Return exit code from dlclose/FreeLibrary * Skip all calls to externs in BlipBufDll when using mono * Use PlatformLinkedLibManager in SevenZipLibraryManager * Add expected return value to workaround (from testing on Win32) * Remove ".dll" from DllImport attr, remove temporary workaround, see desc. The library can be built by changing the output file name in `.../blip_buf/Makefile` to `libblip_buf.so`, and running `make`. It will be loaded if placed in the `.../output` folder. * Remove unused code, add TODO (this class is req. for Waterbox.PeWrapper) The TODO is to [rewrite with C#](https://docs.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files) instead of importing from `kernel32.dll`. * Update OpenTK again but better (for #1384) * Add Mono run script * Add libblip_buf.so (temporary) Temporary because it should be a separate package which BizHawk depends on. * Add distro detection, add "already running" and "unknown distro" messages * Gray-out Lua Console on Unix * Extract superclass from EmuLuaLibrary, add shell implementation for Unix * Specify libdl version, Fedora doesn't have the versionless symlink * Remove empty `ToolStripMenuItem`, null `Text` caused crash on Unix * Transform OpenTK keyboard input into a `List<KeyEvent>` and read that Also fixes crash on rebind * Remove debug `using ...;`
2019-01-03 22:50:55 +00:00
public override void CallFrameAfterEvent()
{
EventsLibrary.CallFrameAfterEvent();
}
Add preliminary Unix compatibility (using Mono; resolves #1384) (#1380) * Move PlatformSpecificLinkedLibs and implementations to common and rename * Specify file ext. at LoadPlatformSpecific call site * Move Client.Common.Global.RunningOnUnix to PlatformLinkedLibSingleton * Inline var Resolver * Use PlatformLinkedLibManager internally * Move plugin load check to LinkedLibManager, use LinkedLibManager * Interpolate * Return exit code from dlclose/FreeLibrary * Skip all calls to externs in BlipBufDll when using mono * Use PlatformLinkedLibManager in SevenZipLibraryManager * Add expected return value to workaround (from testing on Win32) * Remove ".dll" from DllImport attr, remove temporary workaround, see desc. The library can be built by changing the output file name in `.../blip_buf/Makefile` to `libblip_buf.so`, and running `make`. It will be loaded if placed in the `.../output` folder. * Remove unused code, add TODO (this class is req. for Waterbox.PeWrapper) The TODO is to [rewrite with C#](https://docs.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files) instead of importing from `kernel32.dll`. * Update OpenTK again but better (for #1384) * Add Mono run script * Add libblip_buf.so (temporary) Temporary because it should be a separate package which BizHawk depends on. * Add distro detection, add "already running" and "unknown distro" messages * Gray-out Lua Console on Unix * Extract superclass from EmuLuaLibrary, add shell implementation for Unix * Specify libdl version, Fedora doesn't have the versionless symlink * Remove empty `ToolStripMenuItem`, null `Text` caused crash on Unix * Transform OpenTK keyboard input into a `List<KeyEvent>` and read that Also fixes crash on rebind * Remove debug `using ...;`
2019-01-03 22:50:55 +00:00
public override void CallExitEvent(LuaFile lf)
{
EventsLibrary.CallExitEvent(lf);
Add preliminary Unix compatibility (using Mono; resolves #1384) (#1380) * Move PlatformSpecificLinkedLibs and implementations to common and rename * Specify file ext. at LoadPlatformSpecific call site * Move Client.Common.Global.RunningOnUnix to PlatformLinkedLibSingleton * Inline var Resolver * Use PlatformLinkedLibManager internally * Move plugin load check to LinkedLibManager, use LinkedLibManager * Interpolate * Return exit code from dlclose/FreeLibrary * Skip all calls to externs in BlipBufDll when using mono * Use PlatformLinkedLibManager in SevenZipLibraryManager * Add expected return value to workaround (from testing on Win32) * Remove ".dll" from DllImport attr, remove temporary workaround, see desc. The library can be built by changing the output file name in `.../blip_buf/Makefile` to `libblip_buf.so`, and running `make`. It will be loaded if placed in the `.../output` folder. * Remove unused code, add TODO (this class is req. for Waterbox.PeWrapper) The TODO is to [rewrite with C#](https://docs.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files) instead of importing from `kernel32.dll`. * Update OpenTK again but better (for #1384) * Add Mono run script * Add libblip_buf.so (temporary) Temporary because it should be a separate package which BizHawk depends on. * Add distro detection, add "already running" and "unknown distro" messages * Gray-out Lua Console on Unix * Extract superclass from EmuLuaLibrary, add shell implementation for Unix * Specify libdl version, Fedora doesn't have the versionless symlink * Remove empty `ToolStripMenuItem`, null `Text` caused crash on Unix * Transform OpenTK keyboard input into a `List<KeyEvent>` and read that Also fixes crash on rebind * Remove debug `using ...;`
2019-01-03 22:50:55 +00:00
}
public override void Close()
{
FormsLibrary.DestroyAll();
_lua.Close();
_lua = new Lua();
GuiLibrary.Dispose();
}
2013-11-25 00:55:56 +00:00
public Lua SpawnCoroutine(string file)
{
var lua = _lua.NewThread();
var content = File.ReadAllText(file);
var main = lua.LoadString(content, "main");
lua.Push(main); // push main function on to stack for subsequent resuming
//if (NLua.Lua.WhichLua == "NLua")
{
_lua.GetTable("keepalives")[lua] = 1;
//this not being run is the origin of a memory leak if you restart scripts too many times
_lua.Pop();
}
return lua;
}
Add preliminary Unix compatibility (using Mono; resolves #1384) (#1380) * Move PlatformSpecificLinkedLibs and implementations to common and rename * Specify file ext. at LoadPlatformSpecific call site * Move Client.Common.Global.RunningOnUnix to PlatformLinkedLibSingleton * Inline var Resolver * Use PlatformLinkedLibManager internally * Move plugin load check to LinkedLibManager, use LinkedLibManager * Interpolate * Return exit code from dlclose/FreeLibrary * Skip all calls to externs in BlipBufDll when using mono * Use PlatformLinkedLibManager in SevenZipLibraryManager * Add expected return value to workaround (from testing on Win32) * Remove ".dll" from DllImport attr, remove temporary workaround, see desc. The library can be built by changing the output file name in `.../blip_buf/Makefile` to `libblip_buf.so`, and running `make`. It will be loaded if placed in the `.../output` folder. * Remove unused code, add TODO (this class is req. for Waterbox.PeWrapper) The TODO is to [rewrite with C#](https://docs.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files) instead of importing from `kernel32.dll`. * Update OpenTK again but better (for #1384) * Add Mono run script * Add libblip_buf.so (temporary) Temporary because it should be a separate package which BizHawk depends on. * Add distro detection, add "already running" and "unknown distro" messages * Gray-out Lua Console on Unix * Extract superclass from EmuLuaLibrary, add shell implementation for Unix * Specify libdl version, Fedora doesn't have the versionless symlink * Remove empty `ToolStripMenuItem`, null `Text` caused crash on Unix * Transform OpenTK keyboard input into a `List<KeyEvent>` and read that Also fixes crash on rebind * Remove debug `using ...;`
2019-01-03 22:50:55 +00:00
public override void SpawnAndSetFileThread(string pathToLoad, LuaFile lf)
{
lf.Thread = SpawnCoroutine(pathToLoad);
}
public override void ExecuteString(string command)
2015-10-15 23:26:07 +00:00
{
_currThread = _lua.NewThread();
_currThread.DoString(command);
//if (NLua.Lua.WhichLua == "NLua")
_lua.Pop();
2015-10-15 23:26:07 +00:00
}
2019-11-29 18:47:50 +00:00
public override ResumeResult ResumeScript(LuaFile lf)
{
2019-11-29 18:47:50 +00:00
_currThread = lf.Thread;
try
{
LuaLibraryBase.SetCurrentThread(lf);
2019-11-29 18:47:50 +00:00
var execResult = _currThread.Resume(0);
_lua.RunScheduledDisposes();
2017-05-19 14:47:18 +00:00
// not sure how this is going to work out, so do this too
2019-11-29 18:47:50 +00:00
_currThread.RunScheduledDisposes();
_currThread = null;
var result = new ResumeResult();
if (execResult == 0)
{
// terminated
result.Terminated = true;
}
else
{
// yielded
result.WaitForFrame = FrameAdvanceRequested;
}
FrameAdvanceRequested = false;
return result;
}
finally
{
LuaLibraryBase.ClearCurrentThread();
}
}
public static void Print(params object[] outputs)
{
ConsoleLuaLibrary.Log(outputs);
}
private void Frameadvance()
{
FrameAdvanceRequested = true;
2013-11-25 00:55:56 +00:00
_currThread.Yield(0);
}
private void EmuYield()
{
2013-11-25 00:55:56 +00:00
_currThread.Yield(0);
}
public class ResumeResult
{
public bool WaitForFrame { get; set; }
public bool Terminated { get; set; }
}
}
}