lua-users home
lua-l archive

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


Very cool indeed. Perhaps this could be used to differentiate between a key mapped to nil and a nonexistent table:

```lua

NIL_FIELD == {}

debug.setmetatable(nil, {
    __index = function(t, i)
        return NIL_FIELD
    end
})

local this = {}

if this.field.does.NOT.exist == NIL_FIELD then
    print('field does not exist!')
end
```


On Thu, May 1, 2014 at 9:16 PM, Andrew Starks <andrew.starks@trms.com> wrote:
Here is a hack that I like a lot:

```lua

debug.setmetatable(nil, {
    __index = function(t, i)
        return nil
    end
})

local this = {}

if this.field.does.NOT.exist == nil then
    print('no error!')
end

--> no error!
```


--Andrew