[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Safe navigation operator
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 23 Aug 2010 09:37:50 -0300
> > The problem happens (for example) when you use multiple level tables
> > to store configurations. For example, you store something like:
> > config.network.server.url = "xxx"
> > If the parameter is optional, or if you do not want bad surprise, when
> > you want to use it you need to write:
> > if confg.network and config.network.server and config.network.server.url then
> > dosomething(config.network.server.url)
> > End
>
> What about this? (untested code...)
>
> local emptytable = {}
> local function Opt (t) return t or emptytable end
>
> if config.Opt(network).Opt(server).url then
> dosomething(config.network.server.url)
> End
That does not make any sense. I do not know what I was thinking. Sorry
for the noise...
-- Roberto