lua-users home
lua-l archive

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


Each coroutine has a new lua_State*, which is created when the
coroutine is created and destroyed when the coroutine is garbage
collected. So if those coroutines call into the C side, the new
lua_State* will show up there. For C functions exported to Lua, use
whatever lua_State is passed into them, and make sure that functions
it calls do as well.

By default, all lua_States have the same registry. In terms of
performing the callback, you'd probably want to use the main
lua_State, since any others will be yielded and should not have
function calls performed on them.


On Tue, 14 Sep 2004 13:03:44 +0100, Adam D. Moss <adam@gimp.org> wrote:
> Hi!
> 
> One of my sanity asserts in the C api I export to
> Lua is that (sengine == L), where 'sengine' is the
> lua state originally returned by lua_open() and 'L'
> is the state passed as parameter to C functions
> called by Lua.
> 
> This has usually been a safe assertion, but some recent
> insignificant tweaks to my Lua-side code have sometimes
> (temporarily!) made (sengine != L) for some calls, so I think
> that this assumption is not a good one.  This is Lua 5.0.2.
> 
> Under what circumstances might a new lua state pointer
> be used?  I don't use threads, but I do use coroutines;
> is this symptomatic of a lua->C call from a
> coroutine?
> 
> Will my original 'sengine' always be good, up until a
> lua_close()?  The real reason I'm concerned about this
> varying *L pointer is that my lua app registers callbacks
> (funcs put in the registry) with the C-side, and then the
> C-side calls them rather later.  BUT, the C-side calls
> them with the original 'sengine', not the L* at the time
> the callback was registered.  Which of the two lua_States
> should I use the registry of (I assume this doesn't matter),
> but more importantly which of the two lua_States should I
> perform the callback with?
> 
> Thanks,
> --Adam
> 
>