Page MenuHomePhabricator

Scribunto should allow coroutines in Lua
Open, LowPublic

Description

Author: darklama

Description:
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
    coroutine.yield(i);
  end
end);

end

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

[1] https://raw.github.com/mirven/underscore.lua/master/lib/underscore.lua


Version: unspecified
Severity: enhancement

Details

Reference
bz47799

Event Timeline

bzimport raised the priority of this task from to Low.
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

Bump.

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 https://www.wikidata.org/wiki/Module:Iterators that can be composed to make powerful stuffs.

Used it to build a library that implements https://www.w3.org/TR/sparql11-property-paths/ (some kind of regexps on graphs) on Wikibase clients : https://www.wikidata.org/wiki/Module:PropertyPath using iterators on this allows for example to stop after listing a certain number of matches without loading all the items. (edit,
https://www.wikidata.org/w/index.php?title=Module:Iterators&diff=621399261&oldid=621365189 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.