lua-users home
lua-l archive

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


Am 17.12.2013 11:08 schröbte Sir Pogsalot:
On Mon, Dec 16, 2013 at 12:33 AM, Philipp Janda <siffiejoe@gmx.net> wrote:

You probably already know this, but weak tables only work for garbage
collected reference types with explicit constructions[1], e.g. tables and
userdata, but not numbers, booleans, strings, and light C functions.


I didn't actually know that :o  I think it's just something I never
consciously thought about until you mentioned it... how do those others get
collected?  I guess what I wrote still stands for userdata at least?  Where
do threads/coroutines stand in that?

Tables, full userdata, threads, Lua functions, and C closures get collected and removed from a weak table, while booleans, numbers, strings, light userdata, and light C functions stay in the weak table.



The last two implementations listed here[2] don't do that. One uses object
equality and some form of lookup tree, while the other uses object identity
and nested tables. You should add your implementation to that page after
you have fixed the following bug: `func()` and `func(nil)` are mapped to
the same signature.


[...]

I shall have to add mine to that page sometime, I didn't know memoizing
functions was talked about *there*.


It made sense for the first implementation because you could `__call` the cache directly, the following implementations were added later without reorganizing the wiki.

Philipp