Skip to content

Commit 631e5c3

Browse files
committed
Improve how simple (number-indexed) Lua tables are printed
also might change sort order for associative tables in some edge cases
1 parent b6bcd08 commit 631e5c3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/ConsoleLuaLibrary.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ static string SerializeTable(LuaTable lti)
6969
{
7070
var entries = ((IEnumerator<KeyValuePair<object, object/*?*/>>) lti.GetEnumerator()).AsEnumerable()
7171
.ToArray();
72-
return string.Concat(entries.Select(static kvp => $"\"{kvp.Key}\": \"{kvp.Value}\"\n").Order());
72+
Console.WriteLine(entries[0].Key.GetType().FullName);
73+
return string.Concat(entries.All(static kvp => kvp.Key is long)
74+
? entries.OrderBy(static kvp => (long) kvp.Key, Comparer<long>.Default)
75+
.Select(static kvp => $"{kvp.Key}: \"{kvp.Value}\"\n")
76+
: entries.OrderBy(static kvp => kvp.Key)
77+
.Select(static kvp => $"\"{kvp.Key}\": \"{kvp.Value}\"\n"));
7378
}
7479

7580
if (!Tools.Has<LuaConsole>())

0 commit comments

Comments
 (0)