Change memory.getmemorydomainlist() to return a lua table instead of a string

This commit is contained in:
adelikat 2014-05-19 01:06:44 +00:00
parent ddd3512552
commit 059952f0a4
2 changed files with 17 additions and 3 deletions

View File

@ -1,12 +1,20 @@
using System;
using System.Linq;
using LuaInterface;
namespace BizHawk.Client.Common
{
public class MemoryLuaLibrary : LuaLibraryBase
{
private readonly Lua _lua;
private int _currentMemoryDomain; // Main memory by default
public MemoryLuaLibrary(Lua lua)
{
_lua = lua;
}
public override string Name { get { return "memory"; } }
#region Memory Library Helpers
@ -93,9 +101,15 @@ namespace BizHawk.Client.Common
"getmemorydomainlist",
"Returns a string of the memory domains for the loaded platform core. List will be a single string delimited by line feeds"
)]
public string GetMemoryDomainList()
public LuaTable GetMemoryDomainList()
{
return Global.Emulator.MemoryDomains.Aggregate(string.Empty, (current, t) => current + (t.Name + '\n'));
var table = _lua.NewTable();
for (int i = 0; i < Global.Emulator.MemoryDomains.Count; i++)
{
table[i] = Global.Emulator.MemoryDomains[i].Name;
}
return table;
}
[LuaMethodAttributes(

View File

@ -95,7 +95,7 @@ namespace BizHawk.Client.EmuHawk
_guiLibrary.LuaRegister(lua, Docs);
new InputLuaLibrary(_lua).LuaRegister(lua, Docs);
new JoypadLuaLibrary(_lua).LuaRegister(lua, Docs);
new MemoryLuaLibrary().LuaRegister(lua, Docs);
new MemoryLuaLibrary(_lua).LuaRegister(lua, Docs);
new MainMemoryLuaLibrary(_lua).LuaRegister(lua, Docs);
new MovieLuaLibrary(_lua).LuaRegister(lua, Docs);
new NesLuaLibrary().LuaRegister(lua, Docs);