Editing Module:Math
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 5: | Line 5: | ||
]] | ]] | ||
local yesno | local yesno = require('Module:Yesno') | ||
local getArgs = require('Module:Arguments').getArgs | |||
local p = {} -- Holds functions to be returned from #invoke, and functions to make available to other Lua modules. | local p = {} -- Holds functions to be returned from #invoke, and functions to make available to other Lua modules. | ||
Line 142: | Line 143: | ||
local input_number; | local input_number; | ||
if yesno(trap_fraction, true) then -- Returns true for all input except nil, false, "no", "n", "0" and a few others. See [[Module:Yesno]]. | if yesno(trap_fraction, true) then -- Returns true for all input except nil, false, "no", "n", "0" and a few others. See [[Module:Yesno]]. | ||
local pos = string.find(input_string, '/', 1, true); | local pos = string.find(input_string, '/', 1, true); | ||
Line 555: | Line 553: | ||
-- If failed, attempt to evaluate input as an expression | -- If failed, attempt to evaluate input as an expression | ||
if number == nil then | if number == nil then | ||
local | local frame = mw.getCurrentFrame() | ||
if | local attempt = frame:callParserFunction('#expr', number_string) | ||
number = | attempt = tonumber(attempt) | ||
if attempt ~= nil then | |||
number = attempt | |||
number_string = tostring(number) | number_string = tostring(number) | ||
else | else | ||
Line 580: | Line 580: | ||
]] | ]] | ||
local | local function makeWrapper(funcName) | ||
return function(frame) | return function (frame) | ||
local args = getArgs(frame) -- Argument processing is left to Module:Arguments. Whitespace is trimmed and blank arguments are removed. | |||
return wrap[funcName](args) | |||
end | end | ||
end | end | ||
for funcName in pairs(wrap) do | |||
p[funcName] = makeWrapper(funcName) | |||
end | |||
return | return p |