lua table - `__call` doesn't work in my Lua code -
i think simple dummy example file explains more long words
t = {} t.__call = print t.__call(1) t(2) according documentation, since t table, call t, t(2), should redirected call t.__call, t.__call(2). t.__call works fine, no problem, "syntaxic sugar" doesn't. here output of above code :
1 lua: test.lua:4: attempt call global 't' (a table value) stack traceback: test.lua:4: in main chunk [c]: in ? what missing ? why isn't t(2) converted t.__call(2) ?
__call metamethod , should set on table`s metatable, not table itself.
t = {} m = {} m.__call = print setmetatable(t, m) t(2) check out here. see @deduplicator excellent comment more concise way of doing same thing.
Comments
Post a Comment