lua-users home
lua-l archive

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



On 30-Nov-06, at 11:04 AM, lua@zevv.nl wrote:



* On 2006-11-30 Javier Guerra <javier@guerrag.com> wrote  :

On Thursday 30 November 2006 10:40 am, lua@zevv.nl wrote:
For my application, I'd like such an expression to return a nil
value instead of generating an error. Would it be possible to create
such a

what you're asking is basically that:

nil [anything]  => nil instead of an error.  I'd add this one too:

anything [nil]  => nil

currently both forms generate an error, and there's very little hope
that it may change.

I am absolutely not asking anything to change in the default behaviour,
which seems perfectly ok to me. I am just wondering if there is a way to
change this behaviour for this specific table by clever usage of
metatables e.g.

See the technique in http://lua-users.org/wiki/AutoMagicTables

However, that doesn't return nil on unknown keys; it returns a magic'd table. It would be easy enough to produce a check for that, with a slight modification.