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.

I've written a few words about this, and published a generic scheme,
based on the solution used at Lunatic Python for workarounding this
problem, at my blog:

https://moin.conectiva.com.br/GustavoNiemeyer 

-- 
Gustavo Niemeyer
http://niemeyer.net