Module:LuaCall: Difference between revisions
From Test Wiki
Content deleted Content added
You can already force the value to be a string with a leading /, as Template:Nowiki2 already does |
convert "invoke" to do a true #invoke off the parent frame instead of mangling the frame args and attempting to emulate a #invoke as the emulation is error prone and can easily be detected |
||
| Line 144: | Line 144: | ||
--]] |
--]] |
||
function p.invoke(frame) |
function p.invoke(frame) |
||
| ⚫ | |||
local func |
|||
-- get module and function names from parent args if not provided |
|||
local offset |
|||
local pfargs = setmetatable({frame.args[1], frame.args[2]}, {__index = table}) |
|||
if not pfargs[1] then |
|||
local m = require('Module:' .. frame.args[1]) |
|||
pfargs[1], usedpargs[1] = pframe.args[1], true |
|||
| ⚫ | |||
if not pfargs[2] then |
|||
pfargs[2], usedpargs[2] = pframe.args[2], true |
|||
| ⚫ | |||
offset = 0 |
|||
else |
|||
frame.args = frame:getParent().args |
|||
func = m[frame.args[1]] |
|||
offset = 1 |
|||
end |
end |
||
else |
else |
||
| ⚫ | |||
frame.args = frame:getParent().args |
|||
pfargs[2], usedpargs[1] = pframe.args[1], true |
|||
func = require('Module:' .. frame.args[1])[frame.args[2]] |
|||
end |
|||
offset = 2 |
|||
end |
end |
||
-- repack sequential args |
|||
local args = {} |
|||
for |
for i, v in ipairs(pframe.args) do |
||
if not usedpargs[i] then |
|||
pfargs:insert(v) |
|||
usedpargs[i] = true |
|||
end |
|||
end |
|||
-- copy other args |
|||
for k, v in pairs(pframe.args) do |
|||
if not pfargs[k] and not usedpargs[k] then |
|||
pfargs[k], usedpargs[k] = v, true |
|||
end |
|||
end |
end |
||
-- #invoke off parent frame so the new frame has the same parent |
|||
frame.args = args |
|||
return pframe:callParserFunction{name = '#invoke', args = pfargs} |
|||
return func(frame) |
|||
end |
end |
||