From b3703ab91d60ef1aba964e3d5736d26dc44695a2 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Thu, 4 Mar 2021 13:42:09 +0100 Subject: [PATCH] Add table.rope_len for determining length --- table.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/table.lua b/table.lua index 26ee32a..dbdd954 100644 --- a/table.lua +++ b/table.lua @@ -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 = {}