lua-users home
lua-l archive

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


Not to hijack this thread before it takes off, but I think it's useful to generalize the question:

Should the Lua API be extended to (transparently) treat callable objects as functions in the appropriate contexts?

I don't have a definitive answer to that, but I do know that if the Lua API doesn't offer a way to deal with this problem, the code to deal with it will be reimplemented again and again by programmers using Lua.

I've run into this issue myself writing the Lua/APR binding (soon, I promise ;) but in another form: Should non-string objects with a __tostring metamethod be accepted as strings? Intuitively I'd say yes (if it quacks like a duck ...). Does anyone have counter arguments?

This same topic came up in the recent thread `Another example for syntactically lightweight closures', see:

http://lua-users.org/lists/lua-l/2008-02/msg00236.html

I agree with Miles and Steve (the next response) that it could be really useful if the Lua API and standard libraries were to make more use of Lua's metamethods (eating one's own dog food so to speak).

 - Peter Odding

Petite Abeille wrote:
Hello,

Any reason for table.sort to only accept functions as comparator, but not callable tables (i.e. a table with a __call metamethod)?

Cheers,

PA.