Home  

Random  

Nearby  



Log in  



Settings  



Donate  



About Wikipedia  

Disclaimers  



Wikipedia





Module:Val: Difference between revisions





Module  

Talk  



Language  

Watch  

View history  

View source  






Browse history interactively
 Previous editNext edit 
Content deleted Content added
rearrange to remove unnecessary globals; minor tweak
move code from Module:Val/units and use mw.loadData to access it
Line 64:
local misc_tbl = {e=args.e, pre=args.p, suf=args.s, fmt=args.fmt or '', nocat=args.nocategory}
return p._main(number,uncertainty,u_tbl,misc_tbl)
end
 
local function get_builtin_unit(unitcode, definitions)
-- Return table of information for the specified built-in unit, or nil if not known.
-- Each defined unit code must be followed by two spaces (not tab characters).
local _, pos = definitions:find('\n' .. unitcode .. ' ', 1, true)
if pos then
local endline = definitions:find('\n', pos, true)
if endline then
local result = {}
local n = 0
local text = definitions:sub(pos, endline - 1)
for item in (text .. ' '):gmatch('(%S[^\n]-)%s%s') do
if item == 'NOSPACE' then
result.nospace = true
else
n = n + 1
if n == 1 then
result.symbol = item
elseif n == 2 then
result.link = item
else
break
end
end
end
if n == 2 then
return result
end
-- Ignore invalid definition, treating it as a comment.
end
end
end
 
local function get_unit(ucode, value, want_link, want_longscale)
local makeunitdata = requiremw.loadData('Module:Val/units')
local result = want_longscale and
get_builtin_unit(ucode, data.builtin_units_long_scale) or
get_builtin_unit(ucode, data.builtin_units)
local lookup = require('Module:Convert/sandbox')._unit
local convert_unit = lookup(ucode, { value = value, link = want_link })
if result then
-- Have: result.symbol + result.link + result.nospace
if want_link then
result.text = '[[' .. result.link .. '|' .. result.symbol .. ']]'
else
result.text = result.symbol
end
result.sortkey = convert_unit.sortkey
else
result = {
text = convert_unit.text,
sortkey = convert_unit.sortkey,
}
end
return result
end
 
local function makeunit(ucode, options)
-- Return wikitext, sortkey for the requested unit and options.
-- LATER The sortkey does not account for any per unit.
local function bracketed(ucode, text)
return ucode:find('[*./]') and '(' .. text .. ')' or text
end
options = options or {}
local unit = get_unit(ucode, options.value, options.link, options.longscale)
local text = unit.text
local percode = options.per
if percode then
local perunit = get_unit(percode, 0, options.per_link, options.longscale)
text = bracketed(ucode, text) .. '/' .. bracketed(percode, perunit.text)
end
if not unit.nospace then
text = ' ' .. text
end
return text, unit.sortkey
end
 
Line 141 ⟶ 217:
local unit_text
if u_tbl.u then
local makeunit = require('Module:Val/units')
unit_text = makeunit(u_tbl.u,{
link=u_tbl.ul,

Retrieved from "https://en.wikipedia.org/wiki/Module:Val"
 




Languages

 



This page is not available in other languages.
 

Wikipedia




Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Terms of Use

Desktop