Page MenuHomePhabricator

Scribunto should allow coroutines in Lua
Open, LowPublic


Author: darklama

Scribunto should allow coroutines in Lua. The only explanation
I've found for excluding the coroutine package is that
"No application is known for us, so it has not been reviewed
for security." I would like to address lack of application:

underscore.lua[1] provides an assortment of useful functions
that mediawiki wikis can benefit from having available. It
uses coroutines to implement iter and range functions.

A simple coroutine example:

function range(b,e)

return coroutine.wrap(function()
  for i = b, e do


for n in range(1,10) do print(n); end


Version: unspecified
Severity: enhancement



Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 1:18 AM
bzimport set Reference to bz47799.
bzimport added a subscriber: Unknown Object (MLST).
bzimport created this task.Apr 28 2013, 6:36 PM
onei added a subscriber: onei.Mar 11 2015, 8:31 AM
hoo added a subscriber: hoo.May 24 2016, 9:24 AM


Coroutines, for example, are a natural way to iterate through a nested table.

The stdlib project's functional library uses coroutines as well.

TomT0m added a subscriber: TomT0m.EditedJan 17 2018, 9:12 PM

For the iterator usecase, I wrote a library of base iterators : that allows to that can be composed to make powerful stuffs.

Used it to build a library that implements (some kind of regexps on graphs) on Wikibase clients : using iterators on this allows for example to stop after listing a certain number of matches without loading all the items. (edit, just did)
The library does not need coroutines and was actually a HUGE help to implement property paths. I guess I could had a function that acts as a range generator in this to fulfil the usecase in this ticket as a base iterator function.

jeblad added a subscriber: jeblad.Sun, Sep 22, 8:58 AM

I would definitely vote for implementing coroutines, in particular to be able to use Yonaba/Moses.

I would definitely vote for implementing coroutines, in particular to be able to use Yonaba/Moses.

I implemented something like that in without the coroutine module. There is also the Luafun library that does functional stuffs, totally usable in
as a Mediawiki module : without the coroutine module.

My own code is not perfect, as the iterators are statefull however.

Yes, usually it is possible to hack around the problem, but I can't really see a good reason why we should do that. It is far better to use common implementations that are known to work and is well maintained.