(Created page with "local p = {} local bit32 = require( 'bit32' ) local rframe = require( 'module:frame' ) function p.force( f ) return p._force( rframe.args( f ) ) end function p._force( a...") Â |
(Priority) |
||
Line 21: | Line 21: | ||
function p._merge( args ) |
function p._merge( args ) |
||
return bit32.bor( unpack( args ) ) |
return bit32.bor( unpack( args ) ) |
||
+ | end |
||
+ | |||
+ | |||
+ | function p.priority( f ) |
||
+ | return p._priority( rframe.args( f )[0] ) |
||
+ | end |
||
+ | |||
+ | function p._priority( dlc ) |
||
+ | local temp_dlc = dlc |
||
+ | local result = 0 |
||
+ | while temp ~= 0 do |
||
+ | result = result + bit32.band( temp_dlc, 1 ) |
||
+ | temp_dlc = bit32.rshift( temp_dlc, 1 ) |
||
+ | end |
||
+ | return result |
||
end |
end |
||
Revision as of 16:37, 19 January 2020
Documentation for this module may be created at Module:Bit/doc
local p = {}
local bit32 = require( 'bit32' )
local rframe = require( 'module:frame' )
function p.force( f )
return p._force( rframe.args( f ) )
end
function p._force( args )
return bit32.band( unpack( args ) )
end
function p.merge( f )
return p._merge( rframe.args( f ) )
end
function p._merge( args )
return bit32.bor( unpack( args ) )
end
function p.priority( f )
return p._priority( rframe.args( f )[0] )
end
function p._priority( dlc )
local temp_dlc = dlc
local result = 0
while temp ~= 0 do
result = result + bit32.band( temp_dlc, 1 )
temp_dlc = bit32.rshift( temp_dlc, 1 )
end
return result
end
function p.remove( f )
return p._remove( rframe.args( f ) )
end
function p._remove( args )
local result = args[1]
for i = 2, #args do
result = bit32.band( result, bit32.bnot( args[i] ) )
end
return result
end
return p