lua-users home
lua-l archive

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


So, I'm still working on my C++ bridge library.
This time I'm having troubles with `__call` metamethod.

I have userdata object to represent C++ std::function (let's call it
CppFunction). To handle calls it, of course, have `__call` metamethod.

So far so good. However, then another object, using our CppFunction as
its `__call` metamethod appears. When I call this one, error happens.

What are the reasons behind disabling direct `__call` chaining when you
can do so for `__index`? Is there any more elegant solution than
wrapping it into regular Lua function?

Pure Lua code to demonstrate problem:

setmetatable({}, {__call = setmetatable({}, {__call = print})})()

It results in "attempt to call a table value".