Content deleted Content added
use metatables for on-demand calculation of redundant data omitted from convertdata |
shouldbe is a message, not a unit code; try removing "~= nil" for cleaner style |
||
Line 78:
cvt_no_num2 = { 'Need second value', 'general' },
cvt_no_unit = { 'Need name of unit', 'unknown' },
cvt_should_be = { '
cvt_sigfig_pos = { 'sigfig "%s" must be positive', 'general' },
cvt_unknown = { 'Unit "%s" is not known', 'unknown' },
Line 220:
unitcode = unitcode:gsub('_', ' ')
local t = units[unitcode]
if t
if t.shouldbe then
return false, { 'cvt_should_be', t.shouldbe
end
local target = t.target -- nil, or unitcode is an alias for this target
Line 344:
if name:sub(1, 1) == '(' then
pos = name:find(')', 1, true)
if pos
return name:sub(1, pos+1) .. name:sub(pos+2):gsub(' ', '-')
end
elseif name:sub(-1, -1) == ')' then
pos = name:find('(', 1, true)
if pos
return name:sub(1, pos-2):gsub(' ', '-') .. name:sub(pos-1)
end
Line 508:
end
end
if exponent
if #show > maxlen then
show = show:sub(1, maxlen)
Line 756:
args.out_unit = next
next = strip(args[i])
if tonumber(next)
i = i + 1
precision = next
Line 783:
end
if precision == nil then
if tonumber(args[i])
precision = strip(args[i])
i = i + 1
Line 865:
local inscale = in_current.scale
local outscale = out_current.scale
if in_current.invert
if in_current.invert * out_current.invert < 0 then
return 1 / (value * inscale * outscale)
end
return value * (inscale / outscale)
elseif in_current.offset
return (value - in_current.offset) * (inscale / outscale) + out_current.offset
else
Line 889:
-- knowledge of what we are converting.
local invalue, inclean, show, exponent, singular
if info
invalue, inclean = info.value, info.clean
end
Line 966:
local clean, exponent = rawget(self, 'clean'), rawget(self, 'exponent')
local value = tonumber(clean) -- absolute value (any negative sign has been ignored)
if exponent
value = value * 10^exponent
end
Line 1,138:
if lk == 'on' or lk == inout then
local link = link_exceptions[unit_table.symbol] or unit_table.link
if link
id = '[[' .. link .. '|' .. id .. ']]'
end
Line 1,316:
if want_link then
local link = out_current.link
if link
id = '[[' .. link .. '|' .. id .. ']]'
end
Line 1,335:
local result = make_result(info[1])
local range = parms.range
if range
local rtext = range[2]
if type(rtext) == 'table' then
|