lua-users home
lua-l archive

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


> 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) :

Yes indeed, proposed 5 minutes before ;-)
Let me just reposition my post: I am not looking into unblocking a technical situation :) In that case I guess that the easiest way to solve my prb is a 'simple' getter / setter.
My post was rather to sense if such a syntax/behavior would be something to include in the native Lua language. I do not mean that because it is in some other language it should be added into Lua; but when I came across the "safe navigation operator" (they usually have a dedicated syntax, e.g. "?." in Groovy), I found it very handy. Especially for an easy embeddable language (as Lua is), that may be used to parse configuration files.

Still I think that rather adding a new operator to Lua, it would be preferable to enhance __index/__newindex (if possible) in order to enable such behavior. But I realize that it would need to hack in the Lua internals (which I am not familiar with).

Is this a stupid idea?