Page MenuHomePhabricator

Allow modules to return a single function rather than a table
Closed, DeclinedPublic

Description

Author: codecat42

Description:
An #invoke call currently requires two arguments: the module name and the function to call from the table it returns. However, in some cases, modules return only one function (they have a single common "entry point") and the table is technically redundant. An example is Module:nl-verb on en.wiktionary, which exports only the function "export.conjugate" and thus all invocations will be {{#invoke:nl-verb|conjugate|...}}.

It would be nice if, in this case, the module could just return a single function, and the invoke call could forego including the function name. However, this would mean that, if called with {{#invoke:foo|bar|baz}}, then within the function that Module:foo returns, frame.args[1] is now "bar" and frame.args[2] is "baz". This differs from the usual behaviour which would be to call the function "bar" and then frame.args[1] would be "baz". I don't know if that is a problem.


Version: unspecified
Severity: enhancement

Details

Reference
bz45562

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 1:35 AM
bzimport added a project: Scribunto.
bzimport set Reference to bz45562.
bzimport added a subscriber: Unknown Object (MLST).

This would make the #invoke syntax much more confusing, and is trivial to work around. Instead of something like

return function () ... end

just do

return { func = function() ... end }

If you really want to, it is even possible to name the function with the empty string

return { [''] = function() ... end }

And then invoke it with {{#invoke:Module||arg1|arg2|etc}}