Last modified: 2013-03-01 19:59:44 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T47562, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 45562 - Allow modules to return a single function rather than a table
Allow modules to return a single function rather than a table
Status: RESOLVED WONTFIX
Product: MediaWiki extensions
Classification: Unclassified
Scribunto (Other open bugs)
unspecified
All All
: Unprioritized enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-02-28 15:43 UTC by CodeCat
Modified: 2013-03-01 19:59 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description CodeCat 2013-02-28 15:43:58 UTC
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.
Comment 1 Brad Jorsch 2013-03-01 19:59:44 UTC
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}}

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links