From f570dcc91352ca73c6e9962b0c97a5c1d08fe03e Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Tue, 3 Jan 2023 19:43:41 +0100 Subject: [PATCH] Berry `bytes()` now evaluates to `false` if empty (#17585) --- CHANGELOG.md | 1 + lib/libesp32/berry/src/be_byteslib.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f8e98bc7..684ede3d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ## [12.3.1.3] ### Added - Support for PCA9632 4-channel 8-bit PWM driver as light driver by Pascal Heinrich (#17557) +- Berry `bytes()` now evaluates to `false` if empty ### Breaking Changed diff --git a/lib/libesp32/berry/src/be_byteslib.c b/lib/libesp32/berry/src/be_byteslib.c index 6fcd457db..665d630f3 100644 --- a/lib/libesp32/berry/src/be_byteslib.c +++ b/lib/libesp32/berry/src/be_byteslib.c @@ -1125,6 +1125,13 @@ static int m_size(bvm *vm) be_return(vm); } +static int m_tobool(bvm *vm) +{ + buf_impl attr = m_read_attributes(vm, 1); + be_pushbool(vm, attr.len > 0 ? 1 : 0); + be_return(vm); +} + static int m_resize(bvm *vm) { int argc = be_top(vm); @@ -1668,6 +1675,7 @@ void be_load_byteslib(bvm *vm) { "deinit", m_deinit }, { "tostring", m_tostring }, { "asstring", m_asstring }, + { "tobool", m_tobool }, { "fromstring", m_fromstring }, { "tob64", m_tob64 }, { "fromb64", m_fromb64 }, @@ -1714,6 +1722,7 @@ class be_class_bytes (scope: global, name: bytes) { deinit, func(m_deinit) tostring, func(m_tostring) asstring, func(m_asstring) + tobool, func(m_tobool) fromstring, func(m_fromstring) tob64, func(m_tob64) fromb64, func(m_fromb64)