[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: GC Metamethod and Tables
- From: virgil@... (Virgil Smith)
- Date: Tue, 12 Aug 2003 15:48:21 -0500
1. Has Lua been fixed to call the gc metamethod for tables as well as for
2. If the answer is no and there is no plan to, then where does one send
feature requests/explanations (other than to this list)?
3. The Explanation...
A. All the other metamethods work for tables as well as userdatas, why the
B. Tables (as the only aggregators of information in Lua) need finalizers,
not because a table itself inherently needs a finalizer, but because the
items it contains may have cross dependencies (after all a table was used to
group them so they are likely to be related in some way). A finalizer for
the table would make an extremely logical place to head off problems in
finalizing contained items with such cross dependencies.
C. An example...
I started using Lua in version 4, and I made my own dynamic library system
(please keep standard "loadlib" discussions out of this thread). In doing
so I made the same decision that others have suggested and had the result of
a library load be a table containing whatever functions, etc. that the
library offered. In the case that a second request was made to load the
same library I arranged to detect this and return the same previously
created table. Then I relied on the GC system to unload the libraries by
"finalizing" the table through the gc system.
The problem, of course, was that you can't finalize a table, only a
userdata. So I had to include a userdata in the table and then finalized
THAT. The problem here is that the table (and whatever the library put in
it at initialization) is or may be already destroyed. Thus I can't hand the
library finalization procedure the table that the library initialization
procedure created, and any needs to use that data in finalization cannot be
fulfilled. Those needs might have been state saving, debugging support,
statistics logging, or just about anything else. What the needs were
doesn't really matter, the point is that because of an aggregation point
those needs might exist and Lua can NOT support them.
Virgil Smith EMAIL: Virgil@Nomadics.com
Nomadics Inc HTTP: www.Nomadics.com
1024 S. Innovation Way PHONE: 405-372-9535
Stillwater, OK 74074, USA FAX: 405-372-9537