Module:NBlocks: Difference between revisions
From Hacks Guide Wiki
More actions
Created page with "local p = {} local TITLE_ALIGN_SIZE = 0x8000 function roundup(num, align) return math.ceil(num / align) * align end function p.raw_blocks_to_bytes(blocks) return blocks * 128 * 1024 end function p.raw_blocks_to_kilobytes(blocks) return blocks * 128 end function p.raw_blocks_to_megabytes(blocks) return blocks / 8 end function p.raw_bytes_to_blocks(bytes) return bytes / 1024 / 128 end function p.roundup_all_sizes_to_bytes(sizes) total = 0 for i, v in ipairs(s..." |
No edit summary |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 11: | Line 11: | ||
end | end | ||
function p. | function p.raw_blocks_to_kib(blocks) | ||
return blocks * 128 | return blocks * 128 | ||
end | end | ||
function p. | function p.raw_blocks_to_mib(blocks) | ||
return blocks / 8 | return blocks / 8 | ||
end | end | ||
function p.raw_bytes_to_blocks(bytes) | function p.raw_bytes_to_blocks(bytes) | ||
return bytes / 1024 / 128 | return math.ceil(bytes / 1024 / 128) | ||
end | |||
function p.raw_mib_to_blocks(mib) | |||
return math.ceil(mib * 8) | |||
end | |||
function get_display_unit(size) | |||
if size >= 1024 * 1024 * 1024 then | |||
return size / 1024 / 1024 / 1024, 'GiB' | |||
elseif size >= 1024 * 1024 then | |||
return size / 1024 / 1024, 'MiB' | |||
elseif size >= 1024 then | |||
return size / 1024, 'KiB' | |||
else | |||
return size, 'bytes' | |||
end | |||
end | |||
function p.raw_format_bytes(bytes) | |||
-- this needs to do bytes, kib, and gib too | |||
local formatted_size, unit = get_display_unit(tonumber(bytes)) | |||
return string.format("%.2f", formatted_size) .. ' ' .. unit | |||
end | end | ||
| Line 31: | Line 53: | ||
end | end | ||
function p. | function p.blocks_to_bytes(frame) | ||
return | return p.raw_blocks_to_bytes(frame.args[1]) | ||
end | |||
function p.blocks_to_kib(frame) | |||
return p.raw_blocks_to_kib(frame.args[1]) | |||
end | |||
function p.blocks_to_mib(frame) | |||
return p.raw_blocks_to_mib(frame.args[1]) | |||
end | |||
function p.bytes_to_blocks(frame) | |||
return p.raw_bytes_to_blocks(frame.args[1]) | |||
end | |||
function p.mib_to_blocks(frame) | |||
return p.raw_mib_to_blocks(frame.args[1]) | |||
end | |||
function p.format_bytes(frame) | |||
return p.raw_format_bytes(frame.args[1]) | |||
end | end | ||
return p | return p | ||