Module:Convert: Difference between revisions

massive refactor; as much as possible, handle input and output unit in the same way; handle combinations (todo: ftin)
(fix default expressions so they do not use loadstring (not available in Scribunto))
(massive refactor; as much as possible, handle input and output unit in the same way; handle combinations (todo: ftin))
Line 1:
-- Convert a value from one unit of measurement to another.
--[[
-- Example: {{convert|123|lb|kg}} --> 123 pounds (56 kg)
Later TODO Too many items to list, but following are some points:
- Some conversions require two outputs: {{convert|55|nmi|km mi}}.
- Some units have two values: {{convert|3.21|m|ftin}}.
- Some units use the plural name, not the symbol, example:
{{convert|12|ha}} --should give--> 12 hectares (30 acres)
]]
 
-- Conversion data is defined in another module because it is too large
Line 12 ⟶ 7:
local convertdata = require(is_test_run and "convertdata" or "Module:Convertdata")
local units = convertdata.units
local defaultunitsdefault_exceptions = convertdata.defaultunitsdefault_exceptions
local link_exceptions = convertdata.link_exceptions
 
local MINUS = '−' -- Unicode U+2212 MINUS SIGN (UTF-8: e2 88 92)
 
local function strip(text)
Line 128 ⟶ 126:
-- Return text with Unicode minus instead of '-', if present.
if text:sub(1, 1) == '-' then
return '−'MINUS .. text:sub(2)
end
return text
Line 218 ⟶ 216:
 
local function format_number(show, exponent, isnegative)
-- Return wikitexts, tof display the value implied by the arguments:where
-- s = wikitext formatted to display the value implied by the arguments:
-- exponent is nil; and
-- exponent is nil; and
-- show is a string of digits (no sign), with an optional dot;
-- show is a string of digits (no sign), with an optional dot;
-- or:
-- or:
-- exponent is a number (integer) indicating where dot should be;
-- show exponent is a string of digitsnumber (nointeger) signindicating and nowhere dot; thereshould is anbe;
-- show is a impliedstring dotof beforedigits show;(no showsign doesand notno dot; startthere withis '0').an
-- implied dot before show; show does not start with '0').
-- The result:
-- f = true if s uses scientific notation
-- The formatted result:
-- * Includes a Unicode minus if isnegative.
-- * Has numsep inserted where necessary.
Line 233:
local sign
if isnegative then
sign = '−' -- Unicode minusMINUS
else
sign = ''
Line 269:
if exponent > 10 or exponent <= -4 or (exponent == 10 and show ~= '1000000000') then
-- Rounded value satisfies: value >= 1e9 or value < 1e-4 (1e9 = 0.1e10).
return sign .. with_exponent(show, exponent-1), true
end
if exponent >= #show then
Line 339:
local wikitext
if wholestr then
local sign = negative and '−'MINUS or '+'
if negative then
wholestr = change_sign(wholestr)
Line 345:
wikitext = frac2:format(use_minus(wholestr), sign, numstr, denstr)
else
local sign = negative and '−'MINUS or ''
wikitext = frac1:format(sign, numstr, denstr)
end
Line 355:
 
local function extract_number(args, index, which)
-- Return true, info if successfullycan extract a number from the text in args[index].,
-- where info is a table with the result.
-- Otherwise, return false, message.
-- Parameter 'which' (1 or 2) selects which input value is being processed.
-- processed (to select the appropriate error message, if needed).
-- Before processing, the input text is cleaned:
-- * Any thousand separators (valid or not) are removed.
Line 363 ⟶ 365:
-- '-' (if negative) or '' (otherwise).
-- That replaces Unicode minus with '-'.
-- If successful, followingthe elementsreturned ininfo table argscontains arenamed updatedfields:
-- (first row appliesvalue if which == 1,a secondvalid otherwise):number
-- singular = true if value is 1 (to use singular form of units)
-- args.in_value1, args.in_singular1, args.in_clean1, args.in_show1
-- = false if value is -1 (like old template)
-- args.in_value2, args.in_singular2, args.in_clean2, args.in_show2
-- clean = cleaned text with any separators and sign removed
-- Value is a valid number.
-- Singular is trueshow if value is 1 (singular= formtext offormatted unitsfor will be used).output
-- For show:
-- Singular is false if value is -1 (like old template).
-- Clean is cleaned text with any separators and sign removed.
-- Show is text formatted for output:
-- * Thousand separators are inserted.
-- * If negative, a Unicode minus is used; otherwise the sign
Line 392:
end
local propersign, negative
if sign == '−'MINUS or sign == '-' then
propersign = '−' -- Unicode U+2212 MINUS SIGN (UTF-8: e2 88 92)
negative = true
elseif sign == '+' then
Line 414:
end
if show == nil then
singular = (value == 1 and not negative)
show = propersign .. with_separator(clean)
end
Line 420:
value = -value
end
ifreturn whichtrue, == 1 then{
args.in_value1value = value,
args.in_singular1singular = singular,
args.in_clean1clean = clean,
args.in_show1show = show
else}
args.in_value2 = value
args.in_singular2 = singular
args.in_clean2 = clean
args.in_show2 = show
end
return true
end
 
Line 446 ⟶ 440:
 
local function get_parms(pframe)
-- If successful, return true, args, unit where
-- Return true, t where t is a table with all arguments passed to the
-- template converted toargs namedis a table of all arguments, orpassed returnto false,the message.template
-- Except for range, which is nil or aconverted table, theto named args thatarguments, areand
-- added here couldunit be provided byis the userinput of theunit template.table;
-- otherwise, return false, message.
-- Some of the named args that are added here could be provided by the
-- user of the template.
-- MediaWiki removes leading and trailing whitespace from the values of
-- named arguments. However, the values of numbered arguments include any
Line 463 ⟶ 460:
['+/-'] = {'&nbsp;±&nbsp;', '&nbsp;±&nbsp;'},
}
local success, msginfo1, info2
local args = {} -- arguments passed to template
for k, v in pframe:argumentPairs() do
args[k] = v
end
success, msginfo1 = extract_number(args, 1, 1)
if not success then return successfalse, msginfo1 end
local in_unit, precision
local next = strip(args[2])
Line 478 ⟶ 475:
else
args.range = range
success, msginfo2 = extract_number(args, 3, 2)
if not success then return successfalse, msginfo2 end
in_unit = strip(args[4])
i = 5
end
local success, in_unit_table = units:lookup(in_unit, args.sp)
if in_unit == nil then return false, 'Need input unit' end
if not success then return false, in_unit_table end
args.in_unit = in_unit
in_unit_table.valinfo = { info1, info2 } -- info2 is nil if no range
in_unit_table.inout = 'in' -- this is an input unit
next = strip(args[i])
i = i + 1
Line 496 ⟶ 495:
else
precision = next
end
if args.adj == nil and args.sing ~= nil then
args.adj = args.sing -- sing (singular) is apparently an old equivalent of adj
end
if args.adj == 'mid' then
Line 519 ⟶ 521:
end
end
iflocal args.disp == 'x' thenargs.disp
if disp == 'x' then
args.joins = { args[i] or '', args[i+1] or '' }
elseif disp == 's' or disp == '/' then
args.disp = 'slash'
end
args.precision = args.precision or precision -- allow named parameter
returnlocal true,abbr = args.abbr
if abbr == nil then
-- Default is to abbreviate output (use symbol), or input if flipped.
args.abbr = (disp == 'flip') and 'in' or 'out'
else
args.abbr_org = abbr -- original abbr (as entered by user)
if disp == 'flip' then -- 'in' = LHS, 'out' = RHS
if abbr == 'in' then
abbr = 'out'
elseif abbr == 'out' then
abbr = 'in'
end
end
args.abbr = abbr
end
return true, args, in_unit_table
end
 
local function default_precision(inclean, invalue, outvalue, parmsin_current, out_current)
-- Return a default value for precision (an integer like 2, 0, -2).
-- Code follows procedures used in old template.
Line 534 ⟶ 554:
local log10 = math.log10
local prec, minprec, adjust
local in_unit_tableutype = parmsout_current.in_unit_tableutype
local out_unit_table = parms.out_unit_table
local utype = out_unit_table.utype
local fudge = 1e-14 -- {{Order of magnitude}} adds this, so we do too
-- Find fractional digits, handling cases like inclean = '12.345e6'.
local integer, dot, fraction = inclean:match('^(%d*)([' .. config.numdot .. ']?)(%d*)')
if utype == 'temperature' then
-- LATER: Give an error message if (invalue < in_unit_tablein_current.offset): below absolute zero?
adjust = 0
local kelvin = (invalue - in_unit_tablein_current.offset) * in_unit_tablein_current.scale
if kelvin <= 0 then -- can get zero, or small but negative value due to precision problems
minprec = 2
Line 555 ⟶ 573:
return 0
end
if out_unit_tableout_current.symbol == 'ft' and dot == '' then
-- More precision when output ft with integer input value.
adjust = -log10(in_unit_tablein_current.scale)
else
adjust = log10(math.abs(invalue / outvalue))
Line 577 ⟶ 595:
end
 
local function convert(value, in_unitin_current, out_unitout_current)
local inscale = in_unitin_current.scale
local outscale = out_unitout_current.scale
if in_unitin_current.invert ~= nil then
if in_unitin_current.invert * out_unitout_current.invert < 0 then
return 1 / (value * inscale * outscale)
end
return value * (inscale / outscale)
elseif in_unitin_current.offset ~= nil then
return (value - in_unitin_current.offset) * (inscale / outscale) + out_unitout_current.offset
else
return value * (inscale / outscale)
Line 592 ⟶ 610:
end
 
local function cvtround(invalueparms, incleaninfo, parmsin_current, out_current)
-- Return true, show,t singularwhere t is a table with the conversion results; fields:
-- show = rounded, formatted string from converting value in info,
-- where
-- show = '' if invalue is nil or ''. Otherwise:
-- show = rounded, formatted string from converting invalue,
-- using the rounding specified in parms.
-- singular = true if result is positive, and (after rounding)
-- is "1", or like "1.00".;
-- or return true, nil if no value specified;
-- or return false, message if problem.
-- This code combines convert/round because some rounding requires
Line 605 ⟶ 622:
-- TODO Limit values to avoid abuse (for example, can currently set
-- precision to very large values like 999).
local showinvalue, exponentinclean, singular = ''show, nilexponent, falsesingular
if info ~= nil then
invalue, inclean = info.value, info.clean
end
if invalue == nil or invalue == '' then
return true, show, singularnil
end
local outvalue = convert(invalue, parms.in_unit_tablein_current, parms.out_unit_tableout_current)
local isnegative
if outvalue < 0 then
Line 636 ⟶ 656:
show = string.format('%.0f', outvalue)
else
precision = default_precision(inclean, invalue, outvalue, parmsin_current, out_current)
end
if precision then
Line 661 ⟶ 681:
end
end
-- TODO Does following work when exponent ~= nil?
-- What if show = '1000' and exponent = 1 (value = .1000*10^1 = 1)?
-- What if show = '1000' and exponent = 2 (value = .1000*10^2 = 10)?
if (show == '1' or show:match('^1%.0*$') ~= nil) and not isnegative then
-- Use match because on some systems 0.99999999999999999 is 1.0.
singular = true
end
returnlocal trueformatted, is_scientific = format_number(show, exponent, isnegative), singular
return true, {
end
show = formatted,
 
is_scientific = is_scientific,
local function linked(in_id, out_id, parms)
singular = singular,
-- Return in_id, out_id after modifying none, one, or both by replacing
clean = show, -- unformatted show (can be used to calculate rounded value)
-- the text with a wikilink, if requested in template.
exponent = exponent,
local function substitute(link)
}
-- TODO Work out how to insert a reasonable prefix in %s.
return link:gsub('%%s', 'xxx', 1)
end
local lk = parms.lk
if lk == 'in' or lk == 'on' then
local link = parms.in_unit_table.link
if link ~= nil then
link = substitute(link)
in_id = '[[' .. link .. '|' .. in_id .. ']]'
end
end
if lk == 'out' or lk == 'on' then
local link = parms.out_unit_table.link
if link ~= nil then
link = substitute(link)
out_id = '[[' .. link .. '|' .. out_id .. ']]'
end
end
return in_id, out_id
end
 
-- TODO Think about when to use ' ' and when to use '&nbsp;'.
-- Old template always uses nbsp before a unit symbol, but seems inconsistent
-- before a unit name. SomethingTemplate:Convert/LoffAonSoff suggested value 1000 was a thresholdsays
-- "Numbers less than 1,000 is not wrapped nor are unit symbols"
-- (use nbsp for smaller values), but no conclusive results.
-- so 1000 is a threshold (use nbsp for smaller values), but no conclusive results.
-- Possibly a concern is wrapping when using {{convert}} in a table
-- (don't want to force a column to be unnecessarily wide by using nbsp).
local disp_joins = {
['or'] = { ' or ' , '' },
['sqbr-sp'] = { ' [' , ']' },
['commasqbr-nbsp'] = { ', &nbsp;[' , ']' },
['slashcomma'] = { ' /, ' , '' },
['sslash-sp'] = { ' / ' , '' },
['bslash-nbsp'] = { '&nbsp;/ (' , ')' },
['slash-nosp'] = { '/' , '' },
['b'] = { ' (' , ')' },
}
 
Line 765 ⟶ 773:
-- evaluates 'v < 120' as a boolean with result
-- 'smallsuffix' if (value < 120), or 'bigsuffix' otherwise.
local success, default = defaultunits:lookup(default_exceptions[unit_table).symbol] or unit_table.default
if successdefault == nil then
local msg = 'Unit "%s" has no default output unit.[[Category:Convert unknown unit]]'
if default:find('|', 1, true) == nil then
return false, msg:format(unit_table.symbol)
end
if default:find('|', 1, true) == nil then
return true, default
end
local t = {}
default = default .. '|' -- to get last item
for item in default:gmatch('%s*(.-)%s*|') do
table.insert(t, item) -- split on '|', removing leading/trailing whitespace
end
if #t == 3 or #t == 4 then
local success, result = pcall(evaluate_condition, value, t[1])
if success then
default = result and t[2] or t[3]
if #t == 4 then
default = default .. t[4]
end
return true, default
end
local t = {}
default = default .. '|' -- to get last item
for item in default:gmatch('%s*(.-)%s*|') do
table.insert(t, item) -- split on '|', removing leading/trailing whitespace
end
if #t == 3 or #t == 4 then
local success, result = pcall(evaluate_condition, value, t[1])
if success then
default = result and t[2] or t[3]
if #t == 4 then
default = default .. t[4]
end
return true, default
end
end
local msg = 'Unit "%s" has an invalid default.[[Category:Convert unknown unit]]'
default = msg:format(unit_table.prefix .. unit_table.baseunit)
end
local msg = 'Unit "%s" has an invalid default.[[Category:Convert unknown unit]]'
default = msg:format(unit_table.symbol)
return false, default
end
 
local function processmake_id(parms, which, unit_table)
-- Return true,id s(unit wheresymbol s = final wikitext result (or falsename, messagepossibly modified).
-- for value 1 or 2 (which), and 'in' or 'out' (unit_table.inout).
-- TODO Clean up: avoid repeatedly accessing the same field in parms,
local abbr = parms.abbr
-- and avoid the clumsy calculation of items that are not needed.
if abbr == 'values' then
local success, t
return ''
success, t = units:lookup(parms.in_unit, parms.sp)
if success then parms.in_unit_table = t else return success, t end
if parms.out_unit == nil then -- need to catch empty string also?
success, t = get_default(parms.in_value1, parms.in_unit_table)
if success then parms.out_unit = t else return success, t end
end
local inout = unit_table.inout
success, t = units:lookup(parms.out_unit, parms.sp, true)
local valinfo = unit_table.valinfo
if success then parms.out_unit_table = t else return success, t end
local in_utypeabbr_org = parms.in_unit_table.utypeabbr_org
iflocal in_utypeadj ~= parms.out_unit_table.utype thenadj
local disp = parms.disp
local msg = 'Cannot convert "%s" to "%s".[[Category:Convert dimension mismatch]]'
local singular = valinfo[which].singular or (inout == 'in' and adj == 'on')
return false, msg:format(in_utype, parms.out_unit_table.utype)
if unit_table.usename then
-- Old template does something like this.
if inout == 'in' then
if adj ~= 'on' and (abbr_org == 'out' or disp == 'flip') then
local value = valinfo[which].value
singular = (0 < value and value < 1.0001)
end
else
if (abbr_org == 'on') or
(disp == nil and (abbr_org == nil or abbr_org == 'out')) or
(disp == 'flip' and abbr_org == 'in') then
local clean, exponent = valinfo[which].clean, valinfo[which].exponent
local value = tonumber(clean) -- absolute value (any negative sign has been ignored)
if exponent ~= nil then
value = value * 10^exponent
end
singular = (value < 1.0001 and not valinfo[which].is_scientific)
end
end
end
local key_name = 'name2'
if parms.out_unit_table.combination then
local msgkey_symbol = 'Combinations not implemented, "%s"symbol'
if singular then
return false, msg:format(parms.out_unit)
key_name = 'name1'
end
if parms.sp == 'us' or unit_table.sp_us then
local outshow1, outshow2, outsingular1, outsingular2
key_name = key_name .. '_us'
success, outshow1, outsingular1 = cvtround(parms.in_value1, parms.in_clean1, parms)
key_symbol = 'sym_us'
if not success then return success, outshow1 end
success, outshow2, outsingular2 = cvtround(parms.in_value2, parms.in_clean2, parms)
if not success then return success, outshow2 end
local inshow1, inshow2 = parms.in_show1, parms.in_show2
local inkey, outkey = 'name2', 'name2'
local insymkey, outsymkey = 'symbol', 'symbol'
if parms.adj == 'on' then -- TODO how process second input value?
inkey = 'name1'
elseif parms.in_singular1 then -- TODO how process second input value?
inkey = 'name1'
end
local id = unit_table[key_name]
if outsingular1 then
if not unit_table.usename then
outkey = 'name1'
if ( abbr == 'on' or abbr == inout or (abbr == 'mos' and inout == 'out') or
end
(abbr_org == nil and unit_table.utype == 'temperature')) and not
if parms.sp == 'us' or parms.in_unit_table.sp_us then
inkey (abbr_org == inkeynil ..and (disp == '_usor' or disp == 'slash')) then
insymkey id = 'sym_us'unit_table[key_symbol]
end
end
iflocal parms.splk == 'us' or parms.out_unit_table.sp_us thenlk
if lk == 'on' outkeyor lk == outkeyinout .. '_us'then
local link = link_exceptions[unit_table.symbol] or unit_table.link
outsymkey = 'sym_us'
if link ~= nil then
end
id = '[[' .. link .. '|' .. id .. ']]'
if parms.in_unit_table.usename then
insymkey = inkey
end
if parms.out_unit_table.usename then
outsymkey = outkey
end
local in_name = parms.in_unit_table[inkey] -- will not need to calculate all of these
local in_symbol = parms.in_unit_table[insymkey]
local out_name = parms.out_unit_table[outkey]
local out_symbol = parms.out_unit_table[outsymkey]
local abbr = parms.abbr
local in_id, out_id = in_symbol, out_symbol
local istemperature = (in_utype == 'temperature')
if abbr == 'on' then -- all symbols
-- Both symbols.
elseif abbr == 'off' then -- all names
in_id = in_name
out_id = out_name
elseif abbr == 'in' then -- input symbols
-- Both symbols.
elseif abbr == 'out' then -- output symbols [is this just the default?]
if not istemperature then
in_id = in_name
end
elseif abbr == 'values' then -- show only values
-- TODO Probably more needed (no preceding space for a start).
in_id = ''
out_id = ''
elseif abbr == 'mos' then -- for ranges, abbreviate with input unit repeated
-- LATER
else -- default
if not istemperature then
in_id = in_name
end
end
return id
in_id, out_id = linked(in_id, out_id, parms)
end
---BEGIN TO-DO------------Put following in cvtround---------------------
 
local range = parms.range
local function process_input(parms, in_current)
local in_block, in_extra, out_block
-- Processing required once per conversion.
if parms.adj == 'on' then
-- Return block of text to represent input (value/unit).
in_extra = '-' .. hyphenated(in_id) .. parms.mid
local id1 = make_id(parms, 1, in_current)
else
local in_extraextra = '&nbsp;' .. in_id
endlocal result
iflocal rangeadj == nil thenparms.adj
in_block = inshow1
out_block = outshow1
else
in_block = inshow1 .. range[1] .. inshow2
out_block = outshow1 .. range[2] .. outshow2
end
local disp = parms.disp
if disp == 'output only' thenor
disp in_block== 'output number only' or disp == 'number' or
out_blockdisp == out_block'u2' ..or 'disp '== ..'unit2' out_idthen
parms.joinsresult = { '', '' }
elseif disp == 'output number only' or disp == 'number' then
in_block = ''
out_block = out_block
parms.joins = { '', '' }
elseif disp == 'unit' then
if parms.adj == 'on' then
in_blockresult = hyphenated(in_idid1)
else
in_blockresult = in_idid1
end
out_block = ''
parms.joins = { '', '' }
elseif disp == 'unit2' then -- is 'unit2' in old template?
in_block = ''
out_block = out_id
parms.joins = { '', '' }
elseif disp == 'flip' then
in_block = out_block .. '&nbsp;' .. out_id
out_block = in_block .. in_extra
parms.joins = disp_joins['b']
elseif disp == 'x' then
in_block = in_block .. in_extra
out_block = out_block .. '&nbsp;' .. out_id
else
in_blocklocal abbr = in_block parms.. in_extraabbr
out_blocklocal mos = out_block(abbr ..== '&nbsp;mos' .. out_id)
local range = parms.range
parms.joins = disp_joins[disp] or disp_joins['b']
local id = (range == nil) and id1 or make_id(parms, 2, in_current)
if id ~= '' then
if adj == 'on' then
mos = false -- if hyphenated, suppress repeat of unit in a range
extra = '-' .. hyphenated(id) .. parms.mid
else
extra = '&nbsp;' .. id
end
end
local valinfo = in_current.valinfo
if range == nil then
result = valinfo[1].show
else
if mos then
result = valinfo[1].show .. '&nbsp;' .. id1 .. range[1] .. valinfo[2].show
else
result = valinfo[1].show .. range[1] .. valinfo[2].show
end
end
if disp == nil then -- special case the most common setting
parms.joins = disp_joins['b']
elseif disp ~= 'x' then
-- Old template does this.
if disp == 'slash' then
if parms.abbr_org == nil then
disp = 'slash-nbsp'
elseif abbr == 'in' or abbr == 'out' then
disp = 'slash-sp'
else
disp = 'slash-nosp'
end
elseif disp == 'sqbr' then
if abbr == 'on' then
disp = 'sqbr-nbsp'
else
disp = 'sqbr-sp'
end
end
parms.joins = disp_joins[disp] or disp_joins['b']
end
end
return result .. extra
end
 
local function process_one_output(parms, out_current)
-- Processing required for each output unit.
-- Return block of text to represent output (value/unit).
local id1 = make_id(parms, 1, out_current)
local extra = ''
local result
local disp = parms.disp
if disp == 'u2' or disp == 'unit2' then -- 'unit2' is not in old template
if parms.adj == 'on' then
result = hyphenated(id1)
else
result = id1
end
else
local range = parms.range
if not (disp == 'output number only' or disp == 'number') then
local id = (range == nil) and id1 or make_id(parms, 2, out_current)
if id ~= '' then
extra = '&nbsp;' .. id
end
end
local valinfo = out_current.valinfo
if range == nil then
result = valinfo[1].show
else
result = valinfo[1].show .. range[2] .. valinfo[2].show
end
end
return result .. extra
end
 
local function process(parms, in_unit_table)
-- Return true, s where s = final wikitext result (or false, message).
local info = in_unit_table.valinfo
local invalue1 = info[1].value
if parms.out_unit == nil then -- LATER need to catch empty string also?
local success, t = get_default(invalue1, in_unit_table)
if success then parms.out_unit = t else return false, t end
end
local out_unit_table
local success, t = units:lookup(parms.out_unit, parms.sp, true)
if success then out_unit_table = t else return false, t end
if in_unit_table.utype ~= out_unit_table.utype then
local msg = 'Cannot convert "%s" to "%s".[[Category:Convert dimension mismatch]]'
return false, msg:format(in_unit_table.utype, out_unit_table.utype)
end
local outputs = {}
local combos = out_unit_table.combination -- nil or table of unit tables
local imax = combos and #combos or 1 -- 1 (single unit) or number of unit tables
for i = 1, imax do
local success, info1, info2
local out_current = combos and combos[i] or out_unit_table
out_current.inout = 'out'
success, info1 = cvtround(parms, info[1], in_unit_table, out_current)
if not success then return false, info1 end
success, info2 = cvtround(parms, info[2], in_unit_table, out_current)
if not success then return false, info2 end
out_current.valinfo = { info1, info2 }
table.insert(outputs, process_one_output(parms, out_current))
end
local disp = parms.disp
local in_block = process_input(parms, in_unit_table)
local out_block = (disp == 'unit') and '' or table.concat(outputs, '; ')
if disp == 'flip' then
in_block, out_block = out_block, in_block
end
local wikitext = in_block .. parms.joins[1] .. out_block .. parms.joins[2]
parms.in_block = in_block
parms.out_block = out_block
---END TO-DO------------------------------------------------------------
local wikitext = parms.in_block .. parms.joins[1] .. parms.out_block .. parms.joins[2]
if parms.sortable == 'on' then
wikitext = ntsh(parms.in_value1invalue1, parms.debug) .. wikitext
end
return true, wikitext
Line 932 ⟶ 1,003:
 
local p = {}
-- A testing program can set the global variable 'is_test_run'.
-- The following sets global variable 'mw' to simulate what Scribunto will do.
local bodge = require(is_test_run and "mw" or "Module:mw") -- fix up mw.text.tag
Line 939 ⟶ 1,009:
config = get_config(frame)
local pframe = frame:getParent()
local success, parms, text
local success, parms, in_unit_table = get_parms(pframe)
if success then
success, text = process(parms, in_unit_table)
else
text = parms
Anonymous user