I've written up a proposed interface between the MediaWiki parser and Lua:
<https://www.mediawiki.org/wiki/Extension:Scribunto/Parser_interface_design>
In summary: the Lua function is called with a single argument, which
is an object representing the parser interface. The object is roughly
equivalent to a PPFrame.
The object would have a property called "args", which is a table with
its "index" metamethod overridden to provide lazy-initialised access
to the parser function arguments with a brief syntax:
{{#invoke:module|func|name=value}}
function p.func(frame)
return frame.args.name --- returns "value"
end
There would be two methods for recursive preprocessing:
* preprocess() provides basic expansion of wikitext
* callTemplate() provides an API for template invocation, since I
imagine that would otherwise be a common use case for preprocess().
Using preprocess() to expand a template with arbitrary arguments would
be difficult.
Like a normal parser function, the Lua function returns text which is
not modified any further by the preprocessor.
Please see the wiki page for a more detailed description, including
rationale.
Any comments would be greatly appreciated.
-- Tim Starling