Module:Convert: Difference between revisions
Jump to navigation
Jump to search
>WOSlinker No edit summary |
>WOSlinker No edit summary |
||
Line 20: | Line 20: | ||
if val2 == nil then | if val2 == nil then | ||
-- Single value supplied | -- Single value supplied | ||
in_unit = args[2]; | |||
out_unit = args[4]; | |||
if in_unit .. "|" .. out_unit == "°C|°F" then | |||
out1 = val1 * 9 / 5 + 32; | |||
elseif in_unit .. out_unit == "" then | |||
out1 = 1; | |||
elseif in_unit .. out_unit == "" then | |||
out1 = 1; | |||
end | |||
output = val1 .. " " .. in_unit .. " (" .. out1 .. " " .. out_unit .. ")" | |||
else | else | ||
-- Two values supplied | -- Two values supplied | ||
range = args[2]; | |||
in_unit = args[4]; | |||
out_unit = args[5]; | |||
end | end | ||
--error ("Module:Convert is not implemented"); | --error ("Module:Convert is not implemented"); | ||
return | return output | ||
end | end | ||
return p | return p |
Revision as of 13:13, 2 September 2012
Documentation for this module may be created at Module:Convert/doc
--require "mw.text" --require "mw.page" local p = {} -- This is the top-level function called by {{convert}}. function p.main(frame, config, args) local pframe = frame:getParent(); local args = pframe.args; -- the arguments passed TO the {{convert}} template, in the wikitext that instantiates the template local config = frame.args; -- the arguments passed BY the {{convert}} template, in the wikitext of the template itself local output; val1 = tonumber(args[1]); val2 = tonumber(args[3]); if val1 == nil then error ("Module:Convert value not supplied"); return "" end if val2 == nil then -- Single value supplied in_unit = args[2]; out_unit = args[4]; if in_unit .. "|" .. out_unit == "°C|°F" then out1 = val1 * 9 / 5 + 32; elseif in_unit .. out_unit == "" then out1 = 1; elseif in_unit .. out_unit == "" then out1 = 1; end output = val1 .. " " .. in_unit .. " (" .. out1 .. " " .. out_unit .. ")" else -- Two values supplied range = args[2]; in_unit = args[4]; out_unit = args[5]; end --error ("Module:Convert is not implemented"); return output end return p