Chaining __call metamethods

classic Classic list List threaded Threaded
2 messages Options
v
Reply | Threaded
Open this post in threaded view
|

Chaining __call metamethods

v
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".


Reply | Threaded
Open this post in threaded view
|

Re: Chaining __call metamethods

Roberto Ierusalimschy
> 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`? [...]

No good reason, apparently.

-- Roberto