util.dbuffer: Expose length as :len() method, like strings

Ref #1598
This commit is contained in:
Kim Alvefur 2020-10-12 20:20:02 +02:00
parent 687d48da48
commit 8f3d5ab4fb
2 changed files with 2 additions and 0 deletions

View file

@ -42,6 +42,7 @@ describe("util.dbuffer", function ()
assert.truthy(b:write("hello world"));
assert.truthy(b:discard(6));
assert.equal(5, b:length());
assert.equal(5, b:len());
assert.equal("world", b:read(5));
end);
end);

View file

@ -135,6 +135,7 @@ end
function dbuffer_methods:length()
return self._length;
end
dbuffer_methods.len = dbuffer_methods.length; -- strings have :len()
dynamic_buffer_mt.__len = dbuffer_methods.length; -- support # operator
function dbuffer_methods:collapse(bytes)