lua-users home
lua-l archive

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


2010/8/23 Cuero Bugot <cbugot@sierrawireless.com>:
> That's basically where I stopped searching with standard Lua: your example has two 'side effects'. If you access (read) a field that does not exist (ex : return config.toto.tata):
>        it returns a table instead of nil
>        it fills in the config table with empty tables

If all you're interested in is getting nil when indexing nil, you can
do it by setting a metatable on nil itself (I think this trick has
been mentionned on the list in the past) :

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

    print(config.network.server.url) --> prints "nil"

This won't help if you want to assign something to "url", though.

-- 
Julien Cugnière