lua-users home
lua-l archive

Re: Is it valid to ref a function/table/userdata in a coroutine?

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


On Wed, Dec 1, 2010 at 1:03 AM, Javier Guerra Giraldez
<javier@guerrag.com> wrote:
> On Wed, Dec 1, 2010 at 12:51 AM, John Labenski <jlabenski@gmail.com> wrote:
>> but what about refs to locals?
>
> a variable can be local.  a value doesn't have scope.
>
> refs refer to values, not variables
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?
lbaselib.c from 5.1.4
static int luaB_cocreate (lua_State *L) {
 lua_State *NL = lua_newthread(L);
 luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1,
 "Lua function expected");
 lua_pushvalue(L, 1); /* move function to top */
 lua_xmove(L, NL, 1); /* move function from L to NL */
 return 1;
}
Regards,
 John

AltStyle によって変換されたページ (->オリジナル) /