diff --git a/CHANGELOG.md b/CHANGELOG.md index a80efcb83..0e9c3ffb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - ESP32 preliminary support for Matter protocol, milestone 1 (commissioning) by Stephan Hadinger - Basic support for Shelly Pro 4PM - Command ``DhtDelay ,`` to allow user control over high and low delay in microseconds (#17944) +- Berry `int64.fromstring()` to convert a string to an int64 ### Breaking Changed - TM1638 button and led support are handled as virtual switches and relays (#11031) diff --git a/lib/libesp32/berry_int64/src/be_int64_class.c b/lib/libesp32/berry_int64/src/be_int64_class.c index 5cbfa54d2..5b3d3e3c2 100644 --- a/lib/libesp32/berry_int64/src/be_int64_class.c +++ b/lib/libesp32/berry_int64/src/be_int64_class.c @@ -53,6 +53,15 @@ char* int64_tostring(int64_t *i64) { } BE_FUNC_CTYPE_DECLARE(int64_tostring, "s", ".") +int64_t* int64_fromstring(bvm *vm, const char* s) { + int64_t *i64 = (int64_t*)be_malloc(vm, sizeof(int64_t)); + if (i64 == NULL) { be_raise(vm, "memory_error", "cannot allocate buffer"); } + if (s) { *i64 = atoll(s); } + else { *i64 = 0; } + return i64; +} +BE_FUNC_CTYPE_DECLARE(int64_fromstring, "int64", "@s") + int32_t int64_toint(int64_t *i64) { return (int32_t) *i64; } @@ -190,6 +199,7 @@ class be_class_int64 (scope: global, name: int64) { set, ctype_func(int64_set) tostring, ctype_func(int64_tostring) + fromstring, static_ctype_func(int64_fromstring) toint, ctype_func(int64_toint) +, ctype_func(int64_add)