[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Safe navigation operator
- From: Cuero Bugot <cbugot@...>
- Date: Mon, 23 Aug 2010 06:20:34 -0700
> Basically, you create proxy object that builds expression tree it is
> passing through
> (in this case, navigation path), and use __newindex as a trigger for
> needed action.
> To access value, you need to define all sorts of __eq, __tostring, etc
> methods that
> vould return configuration value pointed to by the proxy.
Well, this rise the same prb as Wesley's solution: it returns a table when reading a non existing value (instead of nil).
Defining __eq will not work to make look the returned table as if it were a nil value
Setting a new value in a table is indeed quite feasible, and the very reason is that it is easy to know when it is the final access (because it calls __newindex for the final access). The quite difficult case is rather to read the table:
i.e. return config.network.server.url would return nil if either network, or server or url is nil.