Berry `int64.fromstring()` to convert a string to an int64 (#17953)

This commit is contained in:
s-hadinger 2023-02-15 20:52:02 +01:00 committed by GitHub
parent e1b11a6fe7
commit beb1876815
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -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<sensor> <high_delay>,<low_delay>`` 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)

View File

@ -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)