From 66fca7925cf1ce868ac871bfa088d76c291ffa81 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Thu, 8 Mar 2012 08:00:19 +0200 Subject: [PATCH] Lua: bit.value --- manual.lyx | 16 +++++++++++++++- manual.txt | 12 +++++++++++- src/lua/bit.cpp | 16 +++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/manual.lyx b/manual.lyx index b568e904..b77d5622 100644 --- a/manual.lyx +++ b/manual.lyx @@ -2163,6 +2163,16 @@ There are two special bit positions, true and false, standing for always set bit and always clear bit. \end_layout +\begin_layout Subsubsection +bit.value([number bit1[, number bit2,...]]) +\end_layout + +\begin_layout Standard +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. +\end_layout + \begin_layout Subsection Table gui: \end_layout @@ -2461,7 +2471,7 @@ Returns a new palette (initially all transparent). \end_layout \begin_layout Subsubsection -gui.bitmap_new(number w, number h, boolean direct) +gui.bitmap_new(number w, number h, boolean direct[, bool icolor]) \end_layout \begin_layout Standard @@ -2482,6 +2492,10 @@ h: The height of new bitmap direct: If true, the returned bitmap is dbitmap, otherwise bitmap. \end_layout +\begin_layout Itemize +icolor: Initital fill color (defaults to 0 on BITMAP, -1 on DBITMAP) +\end_layout + \begin_layout Subsubsection gui.bitmap_load(string file) \end_layout diff --git a/manual.txt b/manual.txt index b0341459..fe895910 100644 --- a/manual.txt +++ b/manual.txt @@ -1054,6 +1054,12 @@ Notes: • There are two special bit positions, true and false, standing for always set bit and always clear bit. +8.2.11 bit.value([number bit1[, number bit2,...]]) + +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.3 Table gui: Most of these functions can only be called in on_paint and @@ -1211,7 +1217,8 @@ Draw a bitmap on screen. Parameters: Returns a new palette (initially all transparent). Can be used anywhere. -8.3.15 gui.bitmap_new(number w, number h, boolean direct) +8.3.15 gui.bitmap_new(number w, number h, boolean direct[, bool + icolor]) Returns a new bitmap/dbitmap. Can be used anywhere. Parameters: @@ -1222,6 +1229,9 @@ Returns a new bitmap/dbitmap. Can be used anywhere. Parameters: • direct: If true, the returned bitmap is dbitmap, otherwise bitmap. +• icolor: Initital fill color (defaults to 0 on BITMAP, -1 on + DBITMAP) + 8.3.16 gui.bitmap_load(string file) Returns loaded bitmap/dbitmap (if bitmap, the second return value diff --git a/src/lua/bit.cpp b/src/lua/bit.cpp index abf6dc8d..19f974db 100644 --- a/src/lua/bit.cpp +++ b/src/lua/bit.cpp @@ -102,7 +102,7 @@ namespace } }; - function_ptr_luafun lua_print("bit.extract", [](lua_State* LS, const std::string& fname) -> int { + function_ptr_luafun lua_bextract("bit.extract", [](lua_State* LS, const std::string& fname) -> int { uint64_t num = get_numeric_argument(LS, 1, fname.c_str()); uint64_t ret = 0; for(size_t i = 0;; i++) { @@ -119,6 +119,20 @@ namespace return 1; }); + function_ptr_luafun lua_bvalue("bit.value", [](lua_State* LS, const std::string& fname) -> int { + uint64_t ret = 0; + for(size_t i = 0;; i++) { + if(lua_isnumber(LS, i + 1)) { + uint8_t bit = get_numeric_argument(LS, i + 1, fname.c_str()); + ret |= (1ULL << bit); + } else if(lua_isnil(LS, i + 1)) { + } else + break; + } + lua_pushnumber(LS, ret); + return 1; + }); + lua_symmetric_bitwise bit_none("bit.none"); lua_symmetric_bitwise bit_bnot("bit.bnot"); lua_symmetric_bitwise bit_any("bit.any"); -- 2.11.4.GIT