lua-users home
lua-l archive

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

On Sat, Mar 31, 2007 at 02:47:00AM -0700, Graham Wakefield wrote:
> But this is irrelevant to __gc.  The __gc metamethod, as far as I  
> understand, is supposed to be a kind of callback into C to let you  
> know that the userdata has been collected, so you can free additional  
> resources if necessary.  It makes no sense to expose this method to  
> Lua code.

The close() was only one example of when __gc is useful from lua, its
easy to think of others, like replacing __gc with a hook that frees
other resources inside lua, and then calls the original __gc. And
there's nothing about __gc that requires it to be callback into C, its
just a notification by the garbage collector that an object is no longer
referenced by lua, you can use that notification for whatever purpose
you want.

Lua implements language mechanisms, how you use those mechanisms is up
to you. If you don't want your metatable messed with from lua, lua even
has a mechanism you can use to hide it, you can even hide specific items
in the metatable.

Languages that try too hard to prevent us from slipping also prevent us
from achieving, lua is not such a language.