[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Garbage collection
- From: Shmuel Zeigerman <shmuz@...>
- Date: Sat, 09 Sep 2006 15:00:01 +0200
Lyte _ wrote:
I have some problems with adding a metatable to userdata for garbage
collection. This is what I have now... When i start lua I do the following.
/* set its __gc field */
I then call a factory function from lua which creates an object in C. I
want to be able to free this object the right way when it is not used
anymore, but it does not seem to work. This is what I do in the factory
In the Lua program, I then do something like this.
o = CreateObject()
o = nil
When I run this the function I added to the metatable does not get
called. What am I doing wrong here?
You probably forgot to assign the "__index" field
of the metatable to the metatable itself:
lua_pushvalue(L, -2); /* push metatable */
lua_rawset(L, -3); /* metatable.__index = metatable */