[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Basic question on weak keys
- From: Andrew Starks <andrew.starks@...>
- Date: Wed, 13 Jun 2012 16:59:54 -0500
Hey all, Thank you for your patience with all of my posting today.
I'll keep my question short. I'm having trouble groking weak keys. For
example:
a = setmetatable({},{
__mode = "" -- or anything. Doesn't seem to matter for this example.
})
b = {}
a[b] = "value for a[b] key"
print(a[b], b)
-->value for a[b] key table: 0x00049080
--okay...
b = nil
print(a[b])
--> nil
---------------------
Why nil? I thought that since a[b] was not weak, it would keep it as a
reference? What does __mode ="k" do if an object is collected when it
is used in a table as a key? Can someone be so kind as to provide an
example?
Thanks!
--Andrew Starks