Implement bizstring.split()
This commit is contained in:
parent
3127e6d36c
commit
3d10d67fea
|
@ -1,10 +1,21 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
using LuaInterface;
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public class StringLuaLibrary : LuaLibraryBase
|
public class StringLuaLibrary : LuaLibraryBase
|
||||||
{
|
{
|
||||||
|
private readonly Lua _lua;
|
||||||
|
|
||||||
public override string Name { get { return "bizstring"; } }
|
public override string Name { get { return "bizstring"; } }
|
||||||
|
|
||||||
|
public StringLuaLibrary(Lua lua)
|
||||||
|
{
|
||||||
|
_lua = lua;
|
||||||
|
}
|
||||||
|
|
||||||
[LuaMethodAttributes(
|
[LuaMethodAttributes(
|
||||||
"hex",
|
"hex",
|
||||||
"Converts the number to a string representation of the hexadecimal value of the given number"
|
"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);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
new NesLuaLibrary().LuaRegister(lua, Docs);
|
new NesLuaLibrary().LuaRegister(lua, Docs);
|
||||||
new SavestateLuaLibrary().LuaRegister(lua, Docs);
|
new SavestateLuaLibrary().LuaRegister(lua, Docs);
|
||||||
new SnesLuaLibrary().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);
|
new GameInfoLuaLibrary(_lua).LuaRegister(lua, Docs);
|
||||||
Docs.Sort();
|
Docs.Sort();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue