diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.String.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.String.cs index e74e8b9694..15f5cf31c5 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.String.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.String.cs @@ -1,10 +1,21 @@ using System; +using System.Linq; + +using LuaInterface; + namespace BizHawk.Client.Common { public class StringLuaLibrary : LuaLibraryBase { + private readonly Lua _lua; + public override string Name { get { return "bizstring"; } } + public StringLuaLibrary(Lua lua) + { + _lua = lua; + } + [LuaMethodAttributes( "hex", "Converts the number to a string representation of the hexadecimal value of the given number" @@ -126,5 +137,24 @@ namespace BizHawk.Client.Common { return str.EndsWith(str2); } + + [LuaMethodAttributes( + "split", + "Splits str based on separator into a LuaTable. Separator must be one character!. Same functionality as .NET string.Split() using the RemoveEmptyEntries option" + )] + public LuaTable Split(string str, string separator) + { + var table = _lua.NewTable(); + var splitStr = str.Split( + new char[] { separator.FirstOrDefault() }, + StringSplitOptions.RemoveEmptyEntries); + + for(int i = 0; i < splitStr.Length; i++) + { + table[i] = splitStr[i]; + } + + return table; + } } } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs index b6ae48e9da..f0745defe8 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs @@ -101,7 +101,7 @@ namespace BizHawk.Client.EmuHawk new NesLuaLibrary().LuaRegister(lua, Docs); new SavestateLuaLibrary().LuaRegister(lua, Docs); new SnesLuaLibrary().LuaRegister(lua, Docs); - new StringLuaLibrary().LuaRegister(lua, Docs); + new StringLuaLibrary(_lua).LuaRegister(lua, Docs); new GameInfoLuaLibrary(_lua).LuaRegister(lua, Docs); Docs.Sort(); }