Difference between revisions of "Module:Subpixel list"

From ALttP Speedrunning Wiki
Jump to: navigation, search
Line 24: Line 24:
 
until sub==0
 
until sub==0
  
local l = table.maxn()
+
local l = table.maxn(ret)
 
if l==1 then
 
if l==1 then
 
local a = unpack(ret)
 
local a = unpack(ret)

Revision as of 10:26, 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

	local l = table.maxn(ret)
	if l==1 then
		local a = unpack(ret)
		table.insert(ret, a)
		table.insert(ret, a)
		table.insert(ret, a)
	elseif l==2 then
		local a, b = unpack(ret)
		table.insert(ret, a)
		table.insert(ret, b)
	end

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

return p