[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Can I use __gc metamethod directly from Lua?
- From: "Ram Firestone" <bichir@...>
- Date: Sat, 25 Nov 2006 15:09:40 -0800
__gc only works for userdata values.
> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of
> joseph stewart
> Sent: Saturday, November 25, 2006 3:05 PM
> To: Lua list
> Subject: Can I use __gc metamethod directly from Lua?
>
> Hello all,
>
> I'm developing a library binding and to minimize the amount of 'C'
> code I need to write, I want to have Lua handle the __gc metamethod.
> At first glance, this doesn't appear to do what I want. Here's the
> essence of what I'm doing:
>
> mt = {}
> mt.__gc = function() print("gc me") end
> t = {1,2,3}
> setmetatable(t, mt)
> t = nil
> collectgarbage("collect")
>
> I would expect to see "gc me" printed after the collectgarbage
> function call, but I don't.
>
> Am I completely on the wrong track? I've used __gc from 'C' code and
> more or less get what I expect. Is __gc usable from Lua code?
>
> Thanks in advance for any help! When the library is done, I'll share
> it with y'all.
>
> -joe