Add table.rope_len for determining length

This commit is contained in:
Lars Mueller 2021-03-04 13:42:09 +01:00
parent 7346d27e79
commit b3703ab91d

@ -46,6 +46,16 @@ function rope(table)
return setmetatable(table or {}, rope_metatable)
end
local rope_len_metatable = {__index = {
write = function(self, text)
self.len = self.len + text:len()
end
}}
--> rope for determining length supporting :write(text), .len being the length
function rope_len(len)
return setmetatable({len = len or 0}, rope_len_metatable)
end
function is_circular(table)
assert(type(table) == "table")
local known = {}