lua-users home
lua-l archive

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


Currently you can only assign functions to __call, not tables or userdata with their own __call.

Like so:

Lua 5.2.2  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> t = setmetatable({}, { __call = function () return 42 end })
> = t()
42
> t = setmetatable({}, { __call = setmetatable({}, { __call = function () return 42 end }) })
> = t()
stdin:1: attempt to call global 't' (a table value)
stack traceback:
    stdin:1: in main chunk
    [C]: in ?

I'd like to suggest that for Lua 5.3, __call be made "recursive" on callable objects.  I think a rawcall() would then be necessary to add to the rawlen(), rawequal(), rawset() & rawget() ensemble.

Toodles ~

PS: Pretty sure the changes would be made in lua_callk() or luaD_call()... hmm.