[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Is it valid to ref a function/table/userdata in a coroutine?
- From: Drake Wilson <drake@...>
- Date: Wed, 1 Dec 2010 08:23:24 -0700
Quoth John Labenski <jlabenski@gmail.com>, on 2010-12-01 10:02:24 -0500:
> If you look at the C code for the Lua function coroutine.create(fn),
> you see that it uses lua_xmove() to transfer the coroutine's function
> to the new state. This implies to me that there is some scope, between
> lua_States, for at least function values and that perhaps they have to
> be handled differently than when you are dealing with only one
> lua_State. In other words, I will be refing them from the coroutine
> state to the shared registry state and is that valid?
A coroutine state shares essentially everything with the initial state
except the Lua call stack. They share both registry table and heap,
and are otherwise in the same Lua universe, as opposed to two
separately-opened initial states, which would not be. xmove is just a
convenient way to transfer values from one stack to another since in
the C API all values are manipulated through a Lua stack.
---> Drake Wilson