lua-users home
lua-l archive

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


The simplest solution would probably be to associate threads with unique integers. Wrap coroutine.create such that it generates a new unique integer and stores it in a table, with the newly created thread as (weak) key. With that done, have coroutine.create also look up the creating thread's integer and store it in a different table, with the newly created thread as (weak) key.

Ben

On Wed, Jul 8, 2009 at 2:54 PM, Javier Guerra <javier@guerrag.com> wrote:
On Wed, Jul 8, 2009 at 12:59 PM, Jerome Vuarand<jerome.vuarand@gmail.com> wrote:
> 2009/7/8  <matias.guijarro@free.fr>:
>> I wonder if there is a way to determine the "parent" lua_State
>> of a coroutine, given its own lua_State. In other words, I am
>> trying to find the lua_State a given coroutine has been created
>> from.
>>
>> Is it possible ?
>> For the moment I am stuck.
>
> It is not possible. A coroutine "A" can create a coroutine "B", pass
> it to a coroutine "C", and terminate. "A" was the creator of "B", but
> it no longer exists. There is no coroutine ownership mechanism,
> coroutines are garbage collected objects like tables or functions.

the full creation tree isn't relevant; but knowing that all those
coroutines (or threads, from the C API) belong to the same lua_State
is quite valuable.

--
Javier