[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Safe navigation operator
- From: Julien Cugnière <julien.cugniere@...>
- Date: Mon, 23 Aug 2010 15:17:49 +0200
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