Difference between revisions of "Module:Bit field"

From ALttP Speedrunning Wiki
Jump to: navigation, search
(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...")
 
Line 8: Line 8:
  
 
local ret = mw.html.create('table')
 
local ret = mw.html.create('table')
 +
:addClass('wikitable')
 
:addClass('right-1')
 
:addClass('right-1')
  
Line 21: Line 22:
 
:done()
 
:done()
 
:tag('th')
 
:tag('th')
attr('colspan','2')
+
:attr('colspan','2')
 
:wikitext('Value')
 
:wikitext('Value')
 
:done()
 
:done()

Revision as of 09:07, 16 May 2019

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('wikitable')
					: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