Module:LuaCall: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
Trying to execute one arbitrary Lua built-in library function from a template. Inspired by the guy trying to do string.rep with a module |
debuglog |
||
Line 3: | Line 3: | ||
function p.main(frame) |
function p.main(frame) |
||
local parent=frame.getParent(frame) or {} |
local parent=frame.getParent(frame) or {} |
||
local debuglog="" |
|||
for k,v in pairs(parent.args or {}) do |
for k,v in pairs(parent.args or {}) do |
||
_G[k]=v -- transfer every parameter directly to the global variable table |
_G[k]=v -- transfer every parameter directly to the global variable table |
||
debuglog=debuglog..k.."="..v.."\n" |
|||
end |
end |
||
for k,v in pairs(frame.args or {}) do |
for k,v in pairs(frame.args or {}) do |
||
Line 24: | Line 26: | ||
end |
end |
||
end |
end |
||
if not reserved_function then return debuglog end |
|||
return _G[reserved_function](unpack(reserved_contents or {})) |
return _G[reserved_function](unpack(reserved_contents or {})) |
||
end |
end |
Revision as of 15:41, 17 April 2013
Documentation for this module may be created at Module:LuaCall/doc
local p={}
function p.main(frame)
local parent=frame.getParent(frame) or {}
local debuglog=""
for k,v in pairs(parent.args or {}) do
_G[k]=v -- transfer every parameter directly to the global variable table
debuglog=debuglog..k.."="..v.."\n"
end
for k,v in pairs(frame.args or {}) do
_G[k]=v -- transfer every parameter directly to the global variable table
end
--- Alas Scribunto does NOT implement coroutines, according to
--- http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#string.format
--- this will not stop us from trying to implement one single lousy function call
if _G[1] then
local reserved_function,reserved_contents=mw.ustring.match(_G[1],"^(%s*%a[^%s%(]*)%(([^%)]*)%)%s*$")
local reserved_value={}
local reserved_counter=0
if reserved_contents then
repeat
reserved_counter=reserved_counter+1
reserved_value[reserved_counter]=mw.ustring.match(reserved_contents,"([^%,]+)")
reserved_contents=mw.ustring.match(reserved_contents,"[^%,]+,(.*)$")
until not reserved_contents
end
end
if not reserved_function then return debuglog end
return _G[reserved_function](unpack(reserved_contents or {}))
end
return p