Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Toohool
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} local function trim(s) return mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1") end function p.makeWrapper(func, opts) opts = opts or {} local nullableArgNames = {} for i, v in ipairs(opts.nullable or {}) do nullableArgNames[v] = true end local noTrimArgNames = {} for i, v in ipairs(opts.notrim or opts.noTrim or {}) do noTrimArgNames[v] = true end return function(frame) local origArgs if frame == mw.getCurrentFrame() then -- We're being called via #invoke. If the invoking template passed any args, use -- them. Otherwise, use the args that were passed into the template. origArgs = frame:getParent().args for k, v in pairs(frame.args) do origArgs = frame.args break end else -- We're being called from another module or from the debug console, so assume -- the args are passed in directly. origArgs = frame end local args = {} setmetatable(args, { -- ParserFunctions considers the empty string to be false, so to preserve the previous -- behavior of the template, change any empty arguments to nil, so Lua will consider -- them false too. __index = function(t, k) local v = origArgs[k] if v and not noTrimArgNames[k] then v = trim(v) end if v ~= '' or nullableArgNames[k] then return v else return nil end end, __pairs = function(t) local nextFunc = function(tbl, k) local v repeat k = next(origArgs, k) v = args[k] until (not k) or v return k, v end return nextFunc, t, nil end, __ipairs = function(t) -- TODO end }) return func(args) end end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Toohool/doc
(
edit
)