Binding of Isaac: Rebirth Wiki
m (Hardcode some functions to importve performance?)
m (Undo revision 243486 by Derugon (talk) Really small improvement, not worth the lisibility and maintenance)
Tag: Undo
Line 5: Line 5:
 
local w_frame = require( 'module:frame' )
 
local w_frame = require( 'module:frame' )
 
local w_table = require( 'module:table' )
 
local w_table = require( 'module:table' )
 
local data = mw.loadData( 'module:bit/data' )
 
   
   
 
p['and'] = function ( f )
 
p['and'] = function ( f )
 
return bit32.band( unpack( w_table.map( w_frame.args( f ), tonumber ) ) )
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
 
end
   
Line 41: Line 34:
   
 
p['or'] = function ( f )
 
p['or'] = function ( f )
 
return bit32.bor( unpack( w_table.map( w_frame.args( f ), tonumber ) ) )
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
 
end
   

Revision as of 10:10, 3 May 2021

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' )


p['and'] = function ( f )
	return bit32.band( unpack( w_table.map( w_frame.args( f ), tonumber ) ) )
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 )
	return bit32.bor( unpack( w_table.map( w_frame.args( f ), tonumber ) ) )
end


return p