Module:Bit field

From ALttP Speedrunning Wiki
Revision as of 10:07, 16 May 2019 by Kan (talk | contribs) (Created page with "local p = {} function p.main(frame) local args = frame:getParent().args local max = (args.name16 or args.desc16) and 16 or 8 local hexvalue = max==16 and "$%04X" or "$%02...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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

local p = {}

function p.main(frame)
	local args = frame:getParent().args
	local max = (args.name16 or args.desc16) and 16 or 8

	local hexvalue = max==16 and "$%04X" or "$%02X"

	local ret = mw.html.create('table')
					:addClass('right-1')

	ret	:tag('tr')
			:tag('th')
				:wikitext('Bit')
			:done()
			:tag('th')
				:wikitext('Name')
			:done()
			:tag('th')
				:wikitext('Description')
			:done()
			:tag('th')
				attr('colspan','2')
				:wikitext('Value')
			:done()

	for i=max,1 do
		local v = 2^i
		ret	:tag('tr')
				:tag('td')
					:wikitext(i)
				:done()
				:tag('td')
					:wikitext(args['name'..i] or 'b'..i)
				:done()
				:tag('td')
					:wikitext(args['desc'..i] or 'Unused')
				:done()
				:tag('td')
					:wikitext('2')
					:tag('sup')
						:wikitext(i)
					:done()
				:done()
				:tag('td')
					:attr('title', string.format('%s in decimal', v))
					:wikitext(string.format(hexvalue, v))
				:done()
			:done()
	end

	return ret

end

return p