lua-users home
lua-l archive

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


A simle solution would be to change the way the object refers to the
userdata. Instead of using one "global" weak table, each userdata
creates a new weak table, puts itself into index 1 of this table, and
passes the table to the object. (This table is the equivalent to a "weak
reference" in some other languages).

Another solution is to keep the current global weak table, but to add
another table only to control the indices. This table is strong, and
associates indices being used to true. When a new userdata creates a
new index, it queries this table to check for a free index. Only when
a userdata finalizes, it removes its corresponding index from this table,
and only then that index can be reused.

-- Roberto