Project LUALUBIT implements bitwise operators into Lua programming language directly into core code instead of library module. Based on :
Local Download Link lualubit.zip
new release Lua 5.2 was released, native bitwise operatos no implemented, that`s why:
Rework of lualubit for release Lua 5.2 source code http://sourceforge.net/projects/lualubit/files/operators symetry problem: ( ^ in Lua is power x^y operator, that's why cannot be used for XOR ) logical bitwise and && and & or || or | xor (^^) xor ^^ (^) (power operator x**y) ? logical xor is equivalent in C(no logical xor opp): (!a)^(!b), returns 0,1
using booleans in arithmetic problem: ( standart Lua has strictly separated booleans and numbers ) in lualubit is added conversion function const TValue *luaV_toboolnumber (const TValue *obj, TValue *n) which allow use booleans and numbers in arithmetics: ONLY FOR ADDED OPERATORS ... #ifndef GCW_ALLOW_BOOL_IN_ARITHMETIC FOR ALL ARITHM. OPERATORS ... #ifdef GCW_ALLOW_BOOL_IN_ARITHMETIC
using nil in arithmetic problem: ( standart Lua does not allow use nill in arithmetics) added logical operators ( && || ! ) work like a arithm. operators, returns 0,1 but standart Lua logical operators ( and or not ) works like control structure operators. Recomendation: all is OK, assignments must be checked before arithm.operation.
common problem - why use NEW BITWISE AND LOGICAL OPERATORS: Personal view: Each programming language, I ever work in, has bitwise operators, and logical operators returning explicitly 0,1/false,true (instead of any number). ( assembler,Basic,C,C++,JavaScript,PHP,Perl,Python ... (My)SQL !!! ). And ... I think, Lua is not far away from these languages. (Jan)
But I don't like write a = bit32.bor(bit32.band(5,2345),bit32.band(23,7)) instead of a = 5 & 2345 | 23 & 7 that's why I rework source codes ( lua-5.2.0-beta.tar.gz [NEW] 2011-07-08 http://www.lua.org/work/lua-5.2.0-beta.tar.gz ) to use "native" operators (based on http://www.wra1th.plus.com/lua/risclua.html source code) : band & bor | bxor ^^ lshift << rshift >> bnot ~ and additional logical operators : land && lor || lnot ! All source code changes are dependent on (luaconfig.h) #define GCW_BIT /* GCW_BIT: Use bit library. This extends virtual machine with bitwise operations &,|, ^^, ~, <<, >> and provides corresponding events. Warning! Makes code non-portable. Affects c.lvm, c.lcode, c.lopcodes, c.ltm c.llex, c.lparser, h.lcode, h.lopcodes h.ltm, h.llex, h.luaconf. additionally NUM_logical operators ( return numerical (1,0), not boolean values ) !,&&,|| */ IMPORTANT: in standart Lua is not possible use boolean (true,false) in arithmetical operations, but I need it. On (lvm.c line:375) is it possible (unremark) allow using booleans only for new operators. ------------------------------ Need tests, if all is correct. ------------------------------