Binding of Isaac: Rebirth Wiki
Binding of Isaac: Rebirth Wiki

Documentation for this module may be created at Module:Bit/doc

local p = {}

local bit32 = require( 'bit32' )

local w_frame = require( 'module:frame' )
local w_table = require( 'module:table' )

local data = mw.loadData( 'module:bit/data' )


p['and'] = function ( f )
	local result = 15
	for _, v in ipairs( w_table.map( w_frame.args( f ), tonumber ) ) do
		result = v and v > 0 and data['and'][result][v] or 0
	end
	return result
	--return bit32.band( unpack( args ) )
end


function p.count( f )
    local dlc    = tonumber( w_frame.args( f )[1] ) or 0
    local result = 0
    while dlc ~= 0 do
        result = result + bit32.band( dlc, 1 )
        dlc    = bit32.rshift( dlc, 1 )
    end
    return result
end


function p.mask( f )
	local args   = w_frame.args( f )
	local result = tonumber( args[1] ) or 0
	for i = 2, #args do
		result = bit32.band( result, bit32.bnot( tonumber( args[i] ) ) )
	end
	return result
end


p['or'] = function ( f )
	local result = 0
	for _, v in ipairs( w_table.map( w_frame.args( f ), tonumber ) ) do
		if v and v > 0 then
			result = data['or'][result][v]
		end
	end
	return result
	--return bit32.bor( unpack( w_table.map( w_frame.args( f ), tonumber ) ) )
end


return p