[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How can one decide between 'not set' and 'not existing?
- From: Geoff Leyland <geoff_leyland@...>
- Date: Tue, 24 Jul 2012 15:01:12 +1200
On 24/07/2012, at 2:50 PM, meino.cramer@gmx.de wrote:
> It looks like setting a key in a hash with value nil is the
> same as if the key does not exist at all.
It is exactly the same. Setting a table field to nil is the same as deleting the field.
> How can I decide between both in a program?
You can't. If you need to distinguish between the two, you could try:
null = setmetatable({}, {__tostring=function() return "null" end})
a = { key = null }
print(a.key)
null
But your "null"s will occupy space in the table.