如何将方法添加到表类型?我正在尝试编写一种搜索表值的方法。到目前为止我有。
function table:contains(value)
for _, v in ipairs(self) do
if v == value then return true end
end
return false
end
然而,当我尝试执行以下操作时。
t = {'four', 'five', 'six'}
t:contains('five')
我得到了错误。
stdin:1: attempt to call method 'contains' (a nil value)
有什么建议么?