Difference between revisions of "Module:Bit field"
From ALttP Speedrunning Wiki
(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...") |
|||
(4 intermediate revisions by the same user not shown) | |||
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. | + | local max = (args.name15 or args.desc15) and 15 or 7 |
− | local hexvalue = max== | + | local hexvalue = max==15 and "$%04X" or "$%02X" |
local ret = mw.html.create('table') | local ret = mw.html.create('table') | ||
+ | :addClass('wikitable') | ||
+ | :addClass('middlealign') | ||
:addClass('right-1') | :addClass('right-1') | ||
+ | |||
+ | if args.title then | ||
+ | ret :tag('caption') | ||
+ | :wikitext(args.title) | ||
+ | :done() | ||
+ | end | ||
ret :tag('tr') | ret :tag('tr') | ||
Line 21: | Line 29: | ||
:done() | :done() | ||
:tag('th') | :tag('th') | ||
− | attr('colspan','2') | + | :attr('colspan','2') |
:wikitext('Value') | :wikitext('Value') | ||
:done() | :done() | ||
− | for i=max,1 do | + | for i=max,0,-1 do |
local v = 2^i | local v = 2^i | ||
ret :tag('tr') | ret :tag('tr') |
Latest revision as of 09:25, 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('middlealign') :addClass('right-1') if args.title then ret :tag('caption') :wikitext(args.title) :done() end 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