From 0cf0681c1d669aa2d9a22bc585abdc623c0b7092 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Mon, 21 Jan 2013 20:29:36 +0200 Subject: [PATCH] Lua: bit.test_any, bit.test_all --- manual.lyx | 16 ++++++++++++++++ manual.txt | 10 ++++++++++ src/lua/bit.cpp | 14 ++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/manual.lyx b/manual.lyx index ba357c89..8c1c2340 100644 --- a/manual.lyx +++ b/manual.lyx @@ -1406,6 +1406,22 @@ Returns bitwise OR of 1 left shifted by bit1 places, 1 left shifted by bit2 As special value, nil argument is no-op. \end_layout +\begin_layout Subsubsection +bit.test_any(number a, number b) +\end_layout + +\begin_layout Standard +Returns true if bitwise and of a and b is nonzero, otherwise false. +\end_layout + +\begin_layout Subsubsection +bit.test_all(number a, number b) +\end_layout + +\begin_layout Standard +Returns true if bitwise and of a and b is equals b, otherwise false. +\end_layout + \begin_layout Subsection Table gui: \end_layout diff --git a/manual.txt b/manual.txt index b9b0f20b..b8f18b24 100644 --- a/manual.txt +++ b/manual.txt @@ -681,6 +681,16 @@ Returns bitwise OR of 1 left shifted by bit1 places, 1 left shifted by bit2 places and so on. As special value, nil argument is no-op. +8.2.12 bit.test_any(number a, number b) + +Returns true if bitwise and of a and b is nonzero, otherwise +false. + +8.2.13 bit.test_all(number a, number b) + +Returns true if bitwise and of a and b is equals b, otherwise +false. + 8.3 Table gui: Most of these functions can only be called in on_paint and diff --git a/src/lua/bit.cpp b/src/lua/bit.cpp index cb06bc93..620d2333 100644 --- a/src/lua/bit.cpp +++ b/src/lua/bit.cpp @@ -133,6 +133,20 @@ namespace return 1; }); + function_ptr_luafun lua_testany(LS, "bit.test_any", [](lua_state& L, const std::string& fname) -> int { + uint64_t a = L.get_numeric_argument(1, fname.c_str()); + uint64_t b = L.get_numeric_argument(2, fname.c_str()); + L.pushboolean((a & b) != 0); + return 1; + }); + + function_ptr_luafun lua_testall(LS, "bit.test_all", [](lua_state& L, const std::string& fname) -> int { + uint64_t a = L.get_numeric_argument(1, fname.c_str()); + uint64_t b = L.get_numeric_argument(2, fname.c_str()); + L.pushboolean((a & b) == b); + return 1; + }); + lua_symmetric_bitwise bit_none("bit.none"); lua_symmetric_bitwise bit_bnot("bit.bnot"); lua_symmetric_bitwise bit_any("bit.any");