From 9454336f3cf7b9d5719bd0762d7d0b95d8a5bdb2 Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Sat, 27 Jan 2024 13:01:28 +0100 Subject: [PATCH] Berry allow mapping within module (#20606) --- lib/libesp32/berry_tasmota/src/be_ctypes.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/libesp32/berry_tasmota/src/be_ctypes.c b/lib/libesp32/berry_tasmota/src/be_ctypes.c index cd7650d41..d92ffb183 100644 --- a/lib/libesp32/berry_tasmota/src/be_ctypes.c +++ b/lib/libesp32/berry_tasmota/src/be_ctypes.c @@ -255,11 +255,16 @@ int be_ctypes_member(bvm *vm) { if (member->mapping > 0 && definitions->instance_mapping) { const char * mapping_name = definitions->instance_mapping[member->mapping - 1]; if (mapping_name) { - be_getglobal(vm, mapping_name); // stack: class - be_pushvalue(vm, -2); // stack: class, value - be_pushint(vm, -1); // stack; class, value, -1 - be_call(vm, 2); // call constructor with 2 parameters - be_pop(vm, 2); // leave new instance on top of stack + int32_t found = be_find_global_or_module_member(vm, mapping_name); + if (found == 1) { + // we have found only one element from a module, which is expected + be_pushvalue(vm, -2); // stack: class, value + be_pushint(vm, -1); // stack; class, value, -1 + be_call(vm, 2); // call constructor with 2 parameters + be_pop(vm, 2); // leave new instance on top of stack + } else { + be_raisef(vm, "internal_error", "mapping for '%s' not found", mapping_name); + } } } be_return(vm);