lua-users home
lua-l archive

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


On Feb 7, 2008 1:52 PM, Alexander Gladysh <agladysh@gmail.com> wrote:
> You've just made every string callable -- both lambda strings and
> ordinary strings. How would you ensure type-safety now?

The short answer: we can't.  The longer answer is that the requirement
that we test our programs carefully means that type-safety is not so
crucial.

>function call_callback(fn)
>   assert(type(fn) == "function" or type(getmetatable(fn).__call) ==
>"function")
>   fn(42)
> end

And if there were other callables hanging around the system, then one
would have to do that as well, there are going to be tables that are
callable.

BTW, there is a gotcha to this cuteness. Local variables in enclosing
scopes are not respected, alas. Ultimately we really need syntax for
this kind of thing.
steve d.