Changes
get #expr without a frame, don't make unnecessary wrappers, and lazily initialise dependent modules, per protected edit request by User:Jackmcbarn
]]
local yesno = require('Module:Yesno')local getArgs = require('Module:Arguments')., getArgs-- lazily initialized
local p = {} -- Holds functions to be returned from #invoke, and functions to make available to other Lua modules.
local input_number;
if not yesno then
yesno = require('Module:Yesno')
end
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);
-- If failed, attempt to evaluate input as an expression
if number == nil then
local frame success, result = pcall(mw.getCurrentFrame() local attempt = frame:callParserFunction('#ext.ParserFunctions.expr', number_string) attempt = tonumber(attempt) if attempt ~= nil success then number = attempttonumber(result)
number_string = tostring(number)
else
]]
local mt = { __index = function makeWrapper(funcNamet, k) return function (frame) local args if not getArgs then getArgs = require('Module:Arguments').getArgs end return wrap[k](getArgs(frame) ) -- Argument processing is left to Module:Arguments. Whitespace is trimmed and blank arguments are removed. return wrap[funcName](args)
end
end for funcName in pairs(wrap) do p[funcName] = makeWrapper(funcName)end}
return setmetatable(p, mt)