Anonymous user
Module:Convert: Difference between revisions
when input unit is invalid, show input value and unit code plus error message (not just an error message)
(large refactor of messages; show input when only output is invalid (and when reasonably easy to do so)) |
(when input unit is invalid, show input value and unit code plus error message (not just an error message)) |
||
Line 1,524:
-- unit is the input unit table;
-- or return false, t where t is an error message table.
-- The returned input unit table may be for a fake unit using the specified
-- unit code as the symbol and name, and with bad_mcode = message code table.
-- MediaWiki removes leading and trailing whitespace from the values of
-- named arguments. However, the values of numbered arguments include any
Line 1,544 ⟶ 1,546:
i = i + 1
local success, in_unit_table = lookup(in_unit, parms.opt_sp_us, 'no_combination')
if not success then
in_unit_table = setmetatable({ symbol = in_unit, name2 = in_unit, utype = "length", scale = 1, bad_mcode = in_unit_table }, unit_mt)
end
if parms.test == 'msg' then
-- Am testing the messages produced when no output unit is specified, and
Line 2,639 ⟶ 2,643:
linked_pages = {}
local success, bad_output, out_unit_table
local bad_input_mcode = in_unit_table.bad_mcode -- nil if input unit is valid
local invalue1 = in_unit_table.valinfo[1].value
local out_unit = parms.out_unit
if out_unit == nil or out_unit == '' then
if bad_input_mcode then
success, out_unit = get_default(invalue1, in_unit_table)▼
▲ success, out_unit = get_default(invalue1, in_unit_table)
if not success then
bad_output = out_unit
end
end
end
Line 2,658 ⟶ 2,667:
end
end
local flipped = parms.opt_flip and not bad_input_mcode
local parts = {}
for part = 1, 2 do
Line 2,667 ⟶ 2,676:
parts[part] = process_input(parms, in_unit_table)
elseif bad_output then
parts[part] = message(bad_output)
end
else
local outputs = {}
Line 2,694 ⟶ 2,705:
end
local wikitext
if
wikitext = parts[1] .. message(bad_input_mcode)
elseif parms.table_joins then
wikitext = parms.table_joins[1] .. parts[1] .. parms.table_joins[2] .. parts[2]
else
wikitext = parts[1] .. parms.joins[1] .. parts[2] .. parms.joins[2]
end
if parms.warnings and not bad_input_mcode then
wikitext = wikitext .. parms.warnings
end
|