Lua: bit.test_any, bit.test_all

This commit is contained in:
Ilari Liusvaara 2013-01-21 20:29:36 +02:00
parent 9dc3284969
commit 0cf0681c1d
3 changed files with 40 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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<uint8_t>(1, fname.c_str());
uint64_t b = L.get_numeric_argument<uint8_t>(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<uint8_t>(1, fname.c_str());
uint64_t b = L.get_numeric_argument<uint8_t>(2, fname.c_str());
L.pushboolean((a & b) == b);
return 1;
});
lua_symmetric_bitwise<combine_none, BITWISE_MASK> bit_none("bit.none");
lua_symmetric_bitwise<combine_none, BITWISE_MASK> bit_bnot("bit.bnot");
lua_symmetric_bitwise<combine_any, 0> bit_any("bit.any");