lua-users home
lua-l archive

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


> The __call metamethod allows a table to be used as a function.  This
> is similar to C++'s operator () for overloading the function call
> operator on objects.
[...]

As an interesting point, it should be noticed that callable objects
unfortunately are not real functions, and any code that tests for a
function type fails to detect the callable object. For example,
table.foreach() can't receive a callable object as the second
argument.

I've noticed problems like this while working on Lunatic Python. I ended
up implementing the __call method, but also wrapping Python functions
and methods in real Lua function closures, overwhelming these problems.

-- 
Gustavo Niemeyer
http://niemeyer.net