[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: use of invalid L in libevent wrapper from Lua Programming Gems
- From: Wim Couwenberg <wim.couwenberg@...>
- Date: Sat, 19 Dec 2009 12:28:22 +0100
> The wrapper in gem 27 doesn't use L as passed to priv.dispatch(),
> instead it uses some previously-valid L.
You are right. That code implicitly assumes that all events are
created on the state L that calls Event.dispatch() later on. The
cause is this line in the handler function in C-Event.c:
lua_getfield(ev->L, LUA_ENVIRONINDEX, "handle_event");
Here it is assumed that the Lua call frame of the dispatch function
uses ev->L. Another approach could be to store the aux table in the
registry instead of making it the environment of all (private) C
calls. See these lines in the initialize function in C-Event.c:
/* set the "aux" table as environment */
lua_pushvalue(L, 1);
lua_replace(L, LUA_ENVIRONINDEX);
There is another typo in the code in the book. In Event.lua the line
usec = (timeout % 1)*1e9
should be
usec = (timeout % 1)*1e6
Thanks for your feedback.
Bye,
Wim