From 4012f93f31bc3df95d2ff5ddac4a780df8bc6825 Mon Sep 17 00:00:00 2001 From: pasky1382 Date: Tue, 21 Jan 2014 17:28:54 +0000 Subject: [PATCH] Added bit.clear() bit.set() to lua, and LuaULong() --- BizHawk.Client.Common/lua/EmuLuaLibrary.Bit.cs | 15 +++++++++++++-- BizHawk.Client.Common/lua/LuaLibraryBase.cs | 7 ++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Bit.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Bit.cs index 049db9a121..dd2b082973 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Bit.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Bit.cs @@ -19,6 +19,8 @@ namespace BizHawk.Client.Common "ror", "rshift", "check", + "set", + "clear", "byteswap_16", "byteswap_32", "byteswap_64", @@ -70,8 +72,17 @@ namespace BizHawk.Client.Common public static bool bit_check(object num, object pos) { - var value = Convert.ToInt64(LuaLong(num)); - return (value & (1 << (int)(LuaInt(pos)))) != 0; + return (LuaLong(num) & (1 << (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_) diff --git a/BizHawk.Client.Common/lua/LuaLibraryBase.cs b/BizHawk.Client.Common/lua/LuaLibraryBase.cs index e9f26f3d91..c5ccace66b 100644 --- a/BizHawk.Client.Common/lua/LuaLibraryBase.cs +++ b/BizHawk.Client.Common/lua/LuaLibraryBase.cs @@ -38,7 +38,12 @@ namespace BizHawk.Client.Common protected static long LuaLong(object luaArg) { return (long)(double)luaArg; - } + } + + protected static ulong LuaULong(object luaArg) + { + return (ulong)(double)luaArg; + } /// /// LuaInterface requires the exact match of parameter count, except optional parameters.