lua-users home
lua-l archive

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


On Mar 19, 2013, at 11:53 PM, William Sumner <prestonsumner@me.com> wrote:

> One solution might be to introduce an operator for determining if a table contains an element with a given key.

That's what table[ key ] is for.  No point moving the issue around.

__index = error + rawget and Bob's your uncle.  Alternatively, judicious use of assert may have its charms as well.

And you can always use you very own access function, say KABOOM = function( aTable, aKey ) return aTable[ aKey ] or error( 'KABOOM' ) end

print( KABOOM( { a = 1 }, 'b' ) )

In short, the choice is really *yours*.