It was thus said that the Great Lawrence Emke once stated:
> Here is the documentation:
>
> - *__call: *The call operation func(args). This event happens when Lua
> tries to call a non-function value (that is, func is not a function).
> The metamethod is looked up in func. If present, the metamethod is
> called with func as its first argument, followed by the arguments of the
> original call (args). All results of the call are the results of the
> operation. This is the only metamethod that allows multiple results.
Yes. The text could be made a bit clearer that func isn't a function but
some value that has a metatable (like a table or a userdata) with the __call
metamethod in it.
mt = { __call = function(...) print(...) end }
foo = setmetatable({},mt)
bar = setmetatable({},mt)
print(foo) foo(1,2,3)
print(bar) bar(9,8,7)
When I run the above, I get:
table: 0x9682800
table: 0x9682800 1 2 3
table: 0x9682758
table: 0x9682758 9 8 7
> I wrote a constructor "function
obj.new(arg1) .... end
> and I used the standard __call function definition:
>
> setmetatable(obj, { __call = function(cls, ...)
> return
cls.new(...)
> end
> })
>
> When I run the statement
obj.new("this is a test") it works correctly
> If I run it as a call to the object rather than a function in the table
> (e.g ' local abc = obj("this is a test")', the "new" function is called;
> However, the constructor's argument is passed data type of "table".
> This causes the constructor to operate incorrectly.
>
> The fact is lua issues a function call to the __call function that is
> different than what it is suppose to be.
>
> I want to write a general purpose metatable value for the __call function
> value, so the constructor receives the correct parameters.
What are the "correct parameters"? Perhaps if you posted the code you
have, we could help more.
-spc