lua-users home
lua-l archive

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

On Fri, Nov 21, 2008 at 7:31 AM, Florian Weimer <> wrote:
> The PIL XML parser example has this code:

This is a little confusing, could you maybe describe what you are trying to do?

> | static int lxp_parse (lua_State *L) {
> [...]
> |   xpu->L = L;  /* set Lua state */
> The C callbacks use this L as the Lua state for C-to-Lua calls.  I can
> see that this works if the XML parser object is only accessed through
> Lua (before every callback, L is properly initialized).  In a similar

What do you mean by only accessed through lua? These callbacks are
registered into a lua_State (valid, of course), so how could they be
called without that state, L, being properly initialized L?

> case, I would like to avoid this restriction.  Is it sufficient to
> create a new Lua thread and use its state in the callback?  In
> general, I would feel more comfortable about such an approach.

At this point, it sounds like you are intending to call these functions like:

  L = lua_newstate();

but that isn't what they are for. You should just be registering it
with a lua state, and call from lua as