/*
@@ luai_userstate* allow user-specific actions on threads.
** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
** extra when a thread is created/deleted/resumed/yielded.
*/
#define luai_userstateopen(L) ((void)L)
#define luai_userstateclose(L) ((void)L)
#define luai_userstatethread(L,L1) ((void)L)
#define luai_userstatefree(L) ((void)L)
#define luai_userstateresume(L,n) ((void)L)
#define luai_userstateyield(L,n) ((void)L)
These give you a callback on coroutine creation/deletion, that you can use to keep track of the current set of 'live' coroutines.
Other than that, you can put a userdata as the first item on the stack of a coroutine from C, and give the userdata a __gc metamethod. The userdata will stay around on the coroutine's stack until the coroutine is collected (as long as you don't manually remove it).
Marc
On Tue, Dec 14, 2010 at 6:59 PM, Javier Guerra Giraldez
<javier@guerrag.com> wrote:
On Tue, Dec 14, 2010 at 1:45 PM, Zed Shaw <
zed.shaw@gmail.com> wrote:
> Any ideas on how to do that? If it's not possible then I'll probably
> ditch the weak table in favor of something I control myself.
that's the best way.
not only weak tables don't notify eviction, but garbage isn't
collected at the first opportunity. that means that unreachable
values can stay in memory and __gc not called for arbitrary long
times.
if you need something finalized, it's usually better to finalize it yourself.
--
Javier