util.dbuffer: Expose length as :len() method, like strings 0.11
authorKim Alvefur <zash@zash.se>
Mon, 12 Oct 2020 20:20:02 +0200
branch0.11
changeset 11160 a8ef69f7fc35
parent 11146 552cafd30eb2
child 11161 413bd21ba449
util.dbuffer: Expose length as :len() method, like strings Ref #1598
spec/util_dbuffer_spec.lua
util/dbuffer.lua
--- a/spec/util_dbuffer_spec.lua	Wed Oct 07 13:33:02 2020 +0200
+++ b/spec/util_dbuffer_spec.lua	Mon Oct 12 20:20:02 2020 +0200
@@ -42,6 +42,7 @@
 			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);
--- a/util/dbuffer.lua	Wed Oct 07 13:33:02 2020 +0200
+++ b/util/dbuffer.lua	Mon Oct 12 20:20:02 2020 +0200
@@ -135,6 +135,7 @@
 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)