how to inform luals a table with __call() metamethod is also a function? #2168
|
hi folks, i have such usecase and luals 3.6.21 warns me at is there any workaround? thanks in advance. |
Answered by
carsakiller
Jul 3, 2023
Replies: 2 comments 5 replies
|
Something like this works fine: ---@class foo: function
local foo = setmetatable({}, { __call = function() print("foo") end })
---@param fn fun()
local function bar(fn) fn() end
bar(foo)
|
3 replies
|
If you need to define parameters and returns, it is recommended to use ---@overload fun(a: string): boolean
local foo = setmetatable({}, {
__call = function(a)
print(a)
return true
end,
})
local bool = foo("myString") |
2 replies
Answer selected by
haolian9
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you need to define parameters and returns, it is recommended to use
@overload