如何向表类型添加方法?我正在尝试编写一个搜索表值的方法.到目前为止我有.
function table:contains(value)
for _, v in ipairs(self) do
if v == value then return true end
end
return false
end
Run Code Online (Sandbox Code Playgroud)
然而,当我尝试做以下事情时.
t = {'four', 'five', 'six'}
t:contains('five')
Run Code Online (Sandbox Code Playgroud)
我收到了错误.
stdin:1: attempt to call method 'contains' (a nil value)
Run Code Online (Sandbox Code Playgroud)
有什么建议?