Difference between revisions of "Module:Bit field"

From ALttP Speedrunning Wiki
Jump to: navigation, search
Line 3: Line 3:
 
function p.main(frame)
 
function p.main(frame)
 
local args = frame:getParent().args
 
local args = frame:getParent().args
local max = (args.name16 or args.desc16) and 16 or 8
+
local max = (args.name15 or args.desc15) and 15 or 7
  
local hexvalue = max==16 and "$%04X" or "$%02X"
+
local hexvalue = max==15 and "$%04X" or "$%02X"
  
 
local ret = mw.html.create('table')
 
local ret = mw.html.create('table')
Line 26: Line 26:
 
:done()
 
:done()
  
for i=max,1,-1 do
+
for i=max,0,-1 do
 
local v = 2^i
 
local v = 2^i
 
ret :tag('tr')
 
ret :tag('tr')

Revision as of 10:09, 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.name15 or args.desc15) and 15 or 7

	local hexvalue = max==15 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,0,-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