lua-users home
lua-l archive

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


On Thu, Mar 08, 2007 at 10:08:58AM -0300, Roberto Ierusalimschy wrote:
> If you want the gory details, there is another relevant stuff in the

I do! This sounds like it may be useful some day.

> interaction between weak tables and userdata that is missing from the
> manual. Assume a userdata U that has a finalizer (a __gc metamethod).
> If U appears as a value in a weak(value) table, it is removed before
> the calling of its finalizer. But if U appears as a key in a weak(key)
> table, it will be removed only after the calling of its finalizer.
> (This allows the finalizer to access properties related to the userdata
> via a weak table.)

If U is both a key and value then it follows the weak-key rule,
finalize then remove table pair?

	t = setmetatable({},{__mode='kv'})
	U = ... some userdata with a __gc
	t[U] = U
	U=nil
	collectgarbage()
	-- U will be in t until after __gc is called?


Thanks,
Sam