lua-users home
lua-l archive

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


Jan Kratochvíl wrote:

Luiz Henrique de Figueiredo wrote:

I don't know how to mark this coroutine to be garbage collectable?


A coroutine is just like any other Lua value: it is collected when
no references exist for it. So, just make sure no such references
exist and it'll be collected. --lhf
Well, but how? I create it using lua_newthread and so i have only pointer to lua_state. I suppose that mainthread somehow holds reference to this thread but i don't know how to eliminate this reference.

Jan Kratochvil
Illusion softworks, a.s

Ok, one more thing. Can someone explain to me why program below prints out 3 and then 4?
If threads are collected then why aren't the outputs equal?
Progarm is attached here:

#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "stdio.h"

int main (int argc, char *argv[]) {
   lua_State *l = lua_open();
   lua_State *lth;
   const char * a = "local a = 'a'"; //just something

   lua_setgcthreshold(l,0);
   printf("gccount before: %d\n",lua_getgccount(l));

   l2 = lua_newthread(l);

   luaL_loadbuffer(lth,a,strlen(a), "TEST");
   lua_resume(lth,0);

   lua_setgcthreshold(l,0);
   printf("gccount after: %d\n",lua_getgccount(l));

   lua_close(l);
   return 0;
}

Sorry for spaming but i really don't understand this.
Thanks for patience
Jan Kratochvil