Modul:Math: Unterschied zwischen den Versionen
get #expr without a frame, don't make unnecessary wrappers, and lazily initialise dependent modules, per protected edit request by User:Jackmcbarn
(replace frame:preprocess with frame:callParserFunction per protected edit request by User:Jackmcbarn) |
(get #expr without a frame, don't make unnecessary wrappers, and lazily initialise dependent modules, per protected edit request by User:Jackmcbarn) |
||
Zeile 5: | Zeile 5: | ||
]] | ]] | ||
local yesno | local yesno, getArgs -- lazily initialized | ||
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. | ||
Zeile 135: | Zeile 134: | ||
local input_number; | 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]]. | 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); | ||
Zeile 491: | Zeile 493: | ||
-- 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 success, result = pcall(mw.ext.ParserFunctions.expr, number_string) | ||
if success then | |||
number = tonumber(result) | |||
if | |||
number = | |||
number_string = tostring(number) | number_string = tostring(number) | ||
else | else | ||
Zeile 518: | Zeile 518: | ||
]] | ]] | ||
local function | local mt = { __index = function(t, k) | ||
return function (frame) | return function(frame) | ||
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. | |||
end | end | ||
end | end } | ||
return p | return setmetatable(p, mt) |