lua-users home
lua-l archive

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


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.