Binding of Isaac: Rebirth Wiki
m (Undo revision 205988 by Derugon (talk))
Tag: Undo
mNo edit summary
Line 3: Line 3:
 
local bit32 = require( 'bit32' )
 
local bit32 = require( 'bit32' )
   
local rframe = require( 'module:frame' )
+
local w_frame = require( 'module:frame' )
   
   
 
function p.force( f )
 
function p.force( f )
return p._force( rframe.args( f ) )
+
return bit32.band( unpack( w_frame.args( f ) ) )
end
 
 
function p._force( args )
 
return bit32.band( unpack( args ) )
 
 
end
 
end
   
   
 
function p.merge( f )
 
function p.merge( f )
return p._merge( rframe.args( f ) )
+
return bit32.bor( unpack( w_frame.args( f ) ) )
end
 
 
function p._merge( args )
 
return bit32.bor( unpack( args ) )
 
 
end
 
end
   
   
 
function p.priority( f )
 
function p.priority( f )
return p._priority( rframe.args( f )[1] )
+
local dlc = w_frame.args( f )[1]
 
local result = 0
end
 
 
while dlc ~= 0 do
 
 
result = result + bit32.band( dlc, 1 )
function p._priority( dlc )
 
local temp_dlc = dlc
+
dlc = bit32.rshift( dlc, 1 )
local result = 0
 
while temp_dlc ~= 0 do
 
result = result + bit32.band( temp_dlc, 1 )
 
temp_dlc = bit32.rshift( temp_dlc, 1 )
 
 
end
 
end
 
return result
 
return result
Line 40: Line 28:
   
 
function p.remove( f )
 
function p.remove( f )
return p._remove( rframe.args( f ) )
+
local args = w_frame.args( f )
end
 
 
function p._remove( args )
 
 
local result = args[1]
 
local result = args[1]
 
for i = 2, #args do
 
for i = 2, #args do

Revision as of 12:59, 30 March 2020

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

local p = {}

local bit32 = require( 'bit32' )

local w_frame = require( 'module:frame' )


function p.force( f )
	return bit32.band( unpack( w_frame.args( f ) ) )
end


function p.merge( f )
	return bit32.bor( unpack( w_frame.args( f ) ) )
end


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


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


return p