lua-users home
lua-l archive

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


Hi Lua people!

Some years ago I wrote up the following: http://ds9a.nl/webcoding.html

The basic idea is to write code linearly, like this (in sort of
pseudo-basic):

10	print "What is your name?";
20	name=getLine();
25*	if(name=="") then goto 10;
30	print "Your name is: " + name;
50	print "What kind of car do you have?";
60	car=getLine();
65*	if(noSuchCar(car)) then goto 50;
70	print "Insuring a care of make " + car + " costs: ";
100	print carCost(car) + " per year";

Instead of having three (html) pages of code that first ask for your name,
transfer it to a second cgi-script that accepts your name, and aks what kind
of car you have, and then a third script that calculates the price.

To do this using Lua, what I need is something like the following:

    lua_State *L = lua_open();
    luaL_openlibs(L);
    lua_register(L, "getLine", getLine);
    s = lua_pcall(L, 0, LUA_MULTRET, 0);

Once the Lua code calls 'getLine', I'd love for my lua_pcall to return, and
to find somewhere that Lua wants a line, accept that line from somewhere
(webserver, socket, whatever), pass it to lua, and *THEN* make getLine in
Lua return, with that line.

While waiting for that line to appear, thousands of other Lua interpreters
might be processing other lines.

Right now, what I want appears to be impossible, because a return from the
C function getLine is, well, immediate.

What I'd love to be able to do is have getLine set something that makes
lua_pcall return. Then, I'd go off doing various things, push the resulting
line on the stack, and cause processing to continue.

There might be other ways to achieve the same thing (run everything in Lua
with coroutines, for example), but that doesn't fit my current architecture.

If I understand correctly, what I want is possible without special C stack
allocations and everything, but I can't find the machinery to make it
happen.

Any ideas?

-- 
http://www.PowerDNS.com      Open source, database driven DNS Software 
http://netherlabs.nl              Open and Closed source services