lua-users home
lua-l archive

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


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