From f3799fbb0ed7667b54eac27c0423fec1556b1d30 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sat, 24 May 2025 09:56:01 +1000 Subject: [PATCH] Clean up hack in `MemoryLuaLibrary.GetMemoryDomainList` --- src/BizHawk.Client.Common/lua/CommonLibs/MemoryLuaLibrary.cs | 3 +-- src/BizHawk.Client.Common/lua/LuaHelper.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/MemoryLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/MemoryLuaLibrary.cs index c5f71f63b5..4a841adfc7 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/MemoryLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/MemoryLuaLibrary.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -18,7 +17,7 @@ namespace BizHawk.Client.Common [LuaMethodExample("local nlmemget = memory.getmemorydomainlist();")] [LuaMethod("getmemorydomainlist", "Returns a string of the memory domains for the loaded platform core. List will be a single string delimited by line feeds")] public LuaTable GetMemoryDomainList() - => _th.ListToTable((List) APIs.Memory.GetMemoryDomainList(), indexFrom: 0); //HACK cast will succeed as long as impl. returns .Select().ToList() as IROC + => _th.EnumerateToLuaTable(APIs.Memory.GetMemoryDomainList(), indexFrom: 0); [LuaMethodExample("local uimemget = memory.getmemorydomainsize( mainmemory.getname( ) );")] [LuaMethod("getmemorydomainsize", "Returns the number of bytes of the specified memory domain. If no domain is specified, or the specified domain doesn't exist, returns the current domain size")] diff --git a/src/BizHawk.Client.Common/lua/LuaHelper.cs b/src/BizHawk.Client.Common/lua/LuaHelper.cs index 47581e4c18..ed74fbd78a 100644 --- a/src/BizHawk.Client.Common/lua/LuaHelper.cs +++ b/src/BizHawk.Client.Common/lua/LuaHelper.cs @@ -8,6 +8,6 @@ namespace BizHawk.Client.Common public static class LuaExtensions { public static LuaTable EnumerateToLuaTable(this NLuaTableHelper tableHelper, IEnumerable list, int indexFrom = 1) - => tableHelper.ListToTable(list.ToList(), indexFrom); + => tableHelper.ListToTable(list as IReadOnlyList ?? list.ToList(), indexFrom); } }