lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

by way of quick introduction: I am associate professor for Computer Science at Asmara University in Eritrea/NE Africa, and we use Lua quite a bit for teaching and in student software projects!

Recently I have been looking at ways to simplify web programming in a server-side Lua scripting context. Reading up on the functional programming community's ideas, I saw their prevailing idea of using continuations, e.g.

"When the consumer submits a response to this Web form, the browser
issues a request for the URL associated with a continuation. This request and all future requests for the URL resume the continuation with the data from the Web form. In particular, because a Scheme continuation can be invoked an arbitrary number of times, the consumer can respond to the same Web form a multiple number of times and thus resume the script as often as desired." (Matthews et al. 2004:Automatically Restructuring Programs for the Web)

Recall that consumers can respond to the same web forms multiple times _because_ of the Back button and the ability of web browers to clone existing windows and re-submit them. Though it may be debatable, people often think this enriched style of interaction (allowing what-if exploration of web app behaviour) should be supported smoothly.

Lua doesn't have continuations (as first-class values) - a PhD thesis attempt from 2000 posted to lua-l apparently never made it to the Lua mainstream distribution (why not?) and the link http://www.inf.puc-rio.br/~mjulia/luacc.tgz is broken.

You can simulate simplistic continuations to a certain extent with source-to-source transformations that return closures at the (appropriately marked) resumption points, but it's a bit clumsy (and requires more restructuring in the face of loops).

But maybe COROUTINES come close, as also speculated by another post to lua-l? Only problem is: you can't resume the _same_ resumption/yield() point multiple times.

My central question therefore is: How difficult is it to make available the following new primitive

     independentCopyOfCo=coroutine.clone(co) ?

It should be callable at any time during co's life.

With this primitive we could create additional resumption points on demand.

(That demand, i.e. the fact that we are revisiting a page can be detected by the server in the web programming scenario outlined above)

I am not familiar with the innards of Lua at present - can some of the implementors help out with comments on feasibility, whether this makes sense to have for other applications and how to approach an implementation?

--Markus Walther