oop - Regarding colon operator in Lua -
why piece of code fail (attempt call method 'sort' (a nil value))
th> xyz = {1,2,3} th> xyz:sort()
while works
th> table.sort(xyz)
because table
table, contains generic functions manipulating tables provided standard library, isn't in metatable table default. in fact, table doesn't have metatable unless specified explicitly.
you manually though:
local xyz = {1,2,3} local mt = { __index = table} setmetatable(xyz, mt) xyz:insert(2) xyz:sort()
Comments
Post a Comment