lua-users home
lua-l archive

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


Lua's behavior of silently returning nil for undefined variables can lead to bugs that propagate undetected.
 
Maybe there's an interesting little parser patch here.  Say a piece of sugar that converts

   object!.name

to

  (object.name or error("'object' lacks required field 'name'"))

This is the kind of shorthand that's easy to add to the parser, and it seems like it would be handy.  

Of course, now that I've started thinking about it, I'm trying to figure out if I can define a version of the operator that would work well with Peter's table unpack semantic.  Specifically, I'd like to throw informative errors for statements like these:

   local name,size in object!

And that requires a bit more trickery.  At the moment, a transformation along the lines of object! --> (object or _MISSING.object) appears pretty promising.

If anyone else wants this kind of syntax sugar for their own scripts, let me know.  I may have just gone ahead and rolled a quick patch :-)

-Sven