Difference between revisions of "Module:Subpixel list"

From ALttP Speedrunning Wiki
Jump to: navigation, search
Line 7: Line 7:
 
local v = args[1] or '$16'
 
local v = args[1] or '$16'
  
v = tonumber(string.gsub(v, '%$',''), 10) -- remove hex indicator
+
v = string.gsub(v, '%$','') -- remove hex indicator
 +
v = HEX._convert(v, 10, 16)
  
 
local ret = { }
 
local ret = { }

Revision as of 09:21, 15 May 2019

Documentation for this module may be created at list/doc&action=edit&redlink=1 Module:Subpixel list/doc

local p = {}

local HEX = require('Module:Base convert')

function p.main(frame)
	local args = frame:getParent().args
	local v = args[1] or '$16'

	v = string.gsub(v, '%$','') -- remove hex indicator
	v = HEX._convert(v, 10, 16)

	local ret = { }
	local sub = 0

	repeat
		local v1, v2 = v/16, v%16
		v1 = math.floor(v1)
		sub = sub + v2
		if sub>=16 then
			v1 = v1 + math.floor(sub/16)
			sub = sub%16
		end
		table.insert(ret, v1)
	until sub==0

	return table.concat(ret, ',')
end

return p