Added bit.clear() bit.set() to lua, and LuaULong()

This commit is contained in:
pasky1382 2014-01-21 17:28:54 +00:00
parent 8ab655d963
commit 4012f93f31
2 changed files with 19 additions and 3 deletions

View File

@ -19,6 +19,8 @@ namespace BizHawk.Client.Common
"ror", "ror",
"rshift", "rshift",
"check", "check",
"set",
"clear",
"byteswap_16", "byteswap_16",
"byteswap_32", "byteswap_32",
"byteswap_64", "byteswap_64",
@ -70,8 +72,17 @@ namespace BizHawk.Client.Common
public static bool bit_check(object num, object pos) public static bool bit_check(object num, object pos)
{ {
var value = Convert.ToInt64(LuaLong(num)); return (LuaLong(num) & (1 << (LuaInt(pos)))) != 0;
return (value & (1 << (int)(LuaInt(pos)))) != 0; }
public static uint bit_set(object num, object pos)
{
return (uint) (LuaInt(num) | 1 << LuaInt(pos));
}
public static uint bit_clear(object num, object pos)
{
return (uint) (LuaInt(num) & ~(1 << LuaInt(pos)));
} }
public static uint bit_byteswap_16(object short_) public static uint bit_byteswap_16(object short_)

View File

@ -40,6 +40,11 @@ namespace BizHawk.Client.Common
return (long)(double)luaArg; return (long)(double)luaArg;
} }
protected static ulong LuaULong(object luaArg)
{
return (ulong)(double)luaArg;
}
/// <summary> /// <summary>
/// LuaInterface requires the exact match of parameter count, except optional parameters. /// LuaInterface requires the exact match of parameter count, except optional parameters.
/// So, if you want to support variable arguments, declare them as optional and pass /// So, if you want to support variable arguments, declare them as optional and pass