33A simple bit array (or bit set, bit string, boolean vector, ... whatever) data structure for Lua written in pure C.
44
55The data structure Bitarray stores bits (booleans) in an array in a memory-saving manner internally.
6- One can assign value (0 or 1 ) to each element as well as extract values from the array.
6+ One can assign value (false or true ) to each element as well as extract values from the array.
77
8- ## Install from luarocks
8+ * Array bit access using overloaded ` [] ` operators, concatenation with ` .. ` , as well as ` &, |, ~ ` for bit operations (5.3+).
9+ * Object-oriented access. Method chaining is available.
10+ * Conversion between bitarray and unsigned integers (big-endian).
11+
12+ ## Install from [ luarocks] ( https://luarocks.org/modules/cleoold/bitarray )
913It will install the release version.
1014``` sh
1115luarocks install bitarray
@@ -18,7 +22,16 @@ make all LUA_VERSION=5.3 # or 5.1, 5.2
1822The generated shared library will reside in ` out ` folder. Unfortunately, I understand the difficulty of finding the right install path
1923for libraries for different platforms so it is your responsibility to copy the file there. Typically it can be ` /usr/local/lib/lua/5.3/ ` .
2024
25+ ## [ Documentation] ( https://cleoold.github.io/bitarray/doc/ )
26+ Requiring [ ldoc] ( http://stevedonovan.github.io/ldoc/ ) , available by issuing
27+ ``` sh
28+ make doc
29+ ```
30+ It is also available at [ here] ( doc/index.html ) .
31+
2132## Basic usage
33+
34+ Array access
2235``` lua
2336local Bitarray = require ' bitarray'
2437local a = Bitarray .new (10 )
@@ -27,9 +40,32 @@ for i = 1, #a do print(a[i]) end
2740-- true false false false false false false false false false
2841```
2942
30- ## [ Documentation] ( https://cleoold.github.io/bitarray/doc/ )
31- Requiring [ ldoc] ( http://stevedonovan.github.io/ldoc/ ) , available by issuing
32- ``` sh
33- make doc
43+ Method chaining
44+ ``` lua
45+ local b = Bitarray .new (10 )
46+ b :fill (true ):set (1 , false ):set (# b , false )
47+ print (b )
48+ -- Bitarray[0,1,1,1,1,1,1,1,1,0]
3449```
35- It is also available at [ here] ( doc/index.html ) .
50+
51+ Storing integers
52+ ``` lua
53+ local c1 = Bitarray .new (16 ):from_uint16 (65535 )
54+ print (c1 )
55+ -- Bitarray[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
56+ local c2 = Bitarray .new (16 ):from_uint16 (4015 )
57+ print (c2 )
58+ -- Bitarray[0,0,0,0,1,1,1,1,1,0,1,0,1,1,1,1]
59+ local c3 = c1 .. c2
60+ print (c3 )
61+ -- Bitarray[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,1,0,1,1,1,1]
62+ print (c3 :at_uint16 (1 ))
63+ -- 65535
64+ print (c3 :at_uint16 (17 ))
65+ -- 4015
66+ print (c3 :at_uint32 (1 ))
67+ -- 4294905775
68+ ```
69+
70+ ## License
71+ MIT
0 commit comments