Berry bytes() now evaluates to false if empty (#17585)

This commit is contained in:
s-hadinger 2023-01-03 19:43:41 +01:00 committed by GitHub
parent 481cc63bf4
commit f570dcc913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
## [12.3.1.3] ## [12.3.1.3]
### Added ### Added
- Support for PCA9632 4-channel 8-bit PWM driver as light driver by Pascal Heinrich (#17557) - 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 ### Breaking Changed

View File

@ -1125,6 +1125,13 @@ static int m_size(bvm *vm)
be_return(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) static int m_resize(bvm *vm)
{ {
int argc = be_top(vm); int argc = be_top(vm);
@ -1668,6 +1675,7 @@ void be_load_byteslib(bvm *vm)
{ "deinit", m_deinit }, { "deinit", m_deinit },
{ "tostring", m_tostring }, { "tostring", m_tostring },
{ "asstring", m_asstring }, { "asstring", m_asstring },
{ "tobool", m_tobool },
{ "fromstring", m_fromstring }, { "fromstring", m_fromstring },
{ "tob64", m_tob64 }, { "tob64", m_tob64 },
{ "fromb64", m_fromb64 }, { "fromb64", m_fromb64 },
@ -1714,6 +1722,7 @@ class be_class_bytes (scope: global, name: bytes) {
deinit, func(m_deinit) deinit, func(m_deinit)
tostring, func(m_tostring) tostring, func(m_tostring)
asstring, func(m_asstring) asstring, func(m_asstring)
tobool, func(m_tobool)
fromstring, func(m_fromstring) fromstring, func(m_fromstring)
tob64, func(m_tob64) tob64, func(m_tob64)
fromb64, func(m_fromb64) fromb64, func(m_fromb64)