From ad8f321ea130d564fa997410619d896c1ebf469b Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 15 Dec 2019 12:25:49 -0600 Subject: [PATCH] Add event.availableScopes(), fix LogWithSeparator, cleanup --- .../lua/EmuLuaLibrary.Events.cs | 9 +++++++ .../Lua/Libraries/EmuLuaLibrary.Console.cs | 24 ++++++++++++------- BizHawk.sln.DotSettings | 1 + 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs index 418d802b00..9a8edc8ab1 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs @@ -363,6 +363,15 @@ namespace BizHawk.Client.Common return false; } + [LuaMethodExample("local scopes = event.availableScopes();")] + [LuaMethod("availableScopes", "Lists the available scopes that can be passed into memory events")] + public LuaTable AvailableScopes() + { + return DebuggableCore?.MemoryCallbacksAvailable() == true + ? DebuggableCore.MemoryCallbacks.AvailableScopes.ToLuaTable(Lua) + : Lua.NewTable(); + } + private string ProcessScope(string scope) { if (string.IsNullOrWhiteSpace(scope)) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Console.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Console.cs index 248a74442e..44d53dd180 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Console.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Console.cs @@ -71,23 +71,31 @@ namespace BizHawk.Client.EmuHawk // Outputs the given object to the output box on the Lua Console dialog. Note: Can accept a LuaTable private static void LogWithSeparator(string separator, string terminator, params object[] outputs) { - static string SerialiseTable(LuaTable lti) + static string SerializeTable(LuaTable lti) { var keyObjs = lti.Keys; var valueObjs = lti.Values; - if (keyObjs.Count != valueObjs.Count) throw new IndexOutOfRangeException("each value must be paired with one key, they differ in number"); - var values = new List(keyObjs.Count); + if (keyObjs.Count != valueObjs.Count) + { + throw new IndexOutOfRangeException("each value must be paired with one key, they differ in number"); + } + + var values = new object[keyObjs.Count]; var kvpIndex = 0; - foreach (var valueObj in valueObjs) values[kvpIndex++] = valueObj; + foreach (var valueObj in valueObjs) + { + values[kvpIndex++] = valueObj; + } + return string.Concat(keyObjs.Cast() .Select((kObj, i) => $"\"{kObj}\": \"{values[i]}\"\n") .OrderBy(s => s) ); } - static void SerialiseAndWrite(object output) => GlobalWin.Tools.LuaConsole.WriteToOutputWindow( + static void SerializeAndWrite(object output) => GlobalWin.Tools.LuaConsole.WriteToOutputWindow( output is LuaTable table - ? SerialiseTable(table) + ? SerializeTable(table) : output?.ToString() ?? "nil" ); @@ -102,11 +110,11 @@ namespace BizHawk.Client.EmuHawk return; } - SerialiseAndWrite(outputs[0]); + SerializeAndWrite(outputs[0]); for (int outIndex = 1, indexAfterLast = outputs.Length; outIndex != indexAfterLast; outIndex++) { GlobalWin.Tools.LuaConsole.WriteToOutputWindow(separator); - SerialiseAndWrite(outputs[outIndex]); + SerializeAndWrite(outputs[outIndex]); } if (!string.IsNullOrEmpty(terminator)) diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index ba09cb2c36..26f526c14d 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -277,6 +277,7 @@ True True True + True True True True