lua-users home
lua-l archive

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


> Maybe Lua would do well to have a function that check for the
> existence of an operator on a value:
>
>  function g(f,x)
>    assert(hasoperator(f, '__call'), 'f not callable')
>    .....
>    f(x)
>  end

I don't know if the function should be responsible, as implied here,
for checking
"is this a function" (or "is this a table" for __index, and so on),
but I concur:

http://lua-users.org/lists/lua-l/2009-02/msg00078.html

Elaborating on that somewhat: I've been playing with Love2D (http://love2d.org)
for some prototyping these last couple of months, and ported several game
toolkit libraries to it. This has been a perfect opportunity to excise
various of its
dependencies, including many deep-down C bindings, since (unmodified)
Love2D uses pure stock Lua.

A function like the above is the only thing I couldn't finesse without resort to
debug.getmetatable. While that works in this case, I share your concerns in
general, and see "is callable", "is indexable", etc. showing up often enough (in
my own code, old messages on the list I'm much too tired to dig up just now,
recently while perusing Penlight) where this just strikes me as a reasonable
primitive to have "blessed" and put in the library.