aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-10-12 20:20:02 +0200
committerKim Alvefur <zash@zash.se>2020-10-12 20:20:02 +0200
commit8f3d5ab4fb07c14784d8aa4900ac5d184f65ee24 (patch)
treee2b8a156016a261a980bfa2ff7ba3ece37ebdbaa
parent687d48da48e60ff032c43e4c60a6a95a1566838d (diff)
downloadprosody-8f3d5ab4fb07c14784d8aa4900ac5d184f65ee24.tar.gz
prosody-8f3d5ab4fb07c14784d8aa4900ac5d184f65ee24.zip
util.dbuffer: Expose length as :len() method, like strings
Ref #1598
-rw-r--r--spec/util_dbuffer_spec.lua1
-rw-r--r--util/dbuffer.lua1
2 files changed, 2 insertions, 0 deletions
diff --git a/spec/util_dbuffer_spec.lua b/spec/util_dbuffer_spec.lua
index af404042..2b1af835 100644
--- a/spec/util_dbuffer_spec.lua
+++ b/spec/util_dbuffer_spec.lua
@@ -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);
diff --git a/util/dbuffer.lua b/util/dbuffer.lua
index a50f3a64..9d58b306 100644
--- a/util/dbuffer.lua
+++ b/util/dbuffer.lua
@@ -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)