Chaining __call metamethods
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Chaining __call metamethods
- From: v <v19930312@...>
- Date: 2019年6月21日 00:43:12 +0300
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".