This is super advanced stuff… Problem stems from the __index metamethod recursively calling the __call method via t:__call(baz), which triggers the __index again, creating an infinite loop.
Directly call the function without accessing it through t.
local foo = {
__call = function(_, bar)
print(bar)
end,
__index = function(_, baz)
foo.__call(_, baz)
end
}
local qux = setmetatable({}, foo)
qux["foobar"](1, 2, 3)
You do understand I’m scripting off the top of my head here without testing, right?
Just seeing the problem is only 1/2 of the work … try this. (refine, refine, refine)
local foo = {
__call = function(_, bar)
print(bar)
end,
__index = function(t, baz)
t(baz)
end
}
local qux = setmetatable({}, foo)
qux["foobar"](1, 2, 3)