diff --git a/lib/libesp32/Berry/src/be_class.c b/lib/libesp32/Berry/src/be_class.c index 5441b372b..74348fc3f 100644 --- a/lib/libesp32/Berry/src/be_class.c +++ b/lib/libesp32/Berry/src/be_class.c @@ -243,6 +243,20 @@ static int default_init_native_method(bvm *vm) { be_return_nil(vm); } +/* Find instance member by name and copy value to `dst` */ +/* Do not look into virtual members */ +int be_instance_member_simple(bvm *vm, binstance *instance, bstring *name, bvalue *dst) +{ + int type; + be_assert(name != NULL); + binstance * obj = instance_member(vm, instance, name, dst); + type = var_type(dst); + if (obj && type == MT_VARIABLE) { + *dst = obj->members[dst->v.i]; + } + return type; +} + /* Find instance member by name and copy value to `dst` */ /* Input: none of `obj`, `name` and `dst` may not be NULL */ /* Returns the type of the member or BE_NONE if member not found */ diff --git a/lib/libesp32/Berry/src/be_class.h b/lib/libesp32/Berry/src/be_class.h index 3186afd66..6a114f53b 100644 --- a/lib/libesp32/Berry/src/be_class.h +++ b/lib/libesp32/Berry/src/be_class.h @@ -59,6 +59,7 @@ void be_closure_method_bind(bvm *vm, bclass *c, bstring *name, bclosure *cl); int be_class_closure_count(bclass *c); void be_class_upvalue_init(bvm *vm, bclass *c); bbool be_class_newobj(bvm *vm, bclass *c, bvalue *argv, int argc, int mode); +int be_instance_member_simple(bvm *vm, binstance *obj, bstring *name, bvalue *dst); int be_instance_member(bvm *vm, binstance *obj, bstring *name, bvalue *dst); int be_class_member(bvm *vm, bclass *obj, bstring *name, bvalue *dst); bbool be_instance_setmember(bvm *vm, binstance *obj, bstring *name, bvalue *src); diff --git a/lib/libesp32/Berry/src/be_gc.c b/lib/libesp32/Berry/src/be_gc.c index dc5e2d09c..0475de7b3 100644 --- a/lib/libesp32/Berry/src/be_gc.c +++ b/lib/libesp32/Berry/src/be_gc.c @@ -458,7 +458,7 @@ static void destruct_object(bvm *vm, bgcobject *obj) int type; binstance *ins = cast_instance(obj); /* does not GC when creating the string "deinit". */ - type = be_instance_member(vm, ins, str_literal(vm, "deinit"), vm->top); + type = be_instance_member_simple(vm, ins, str_literal(vm, "deinit"), vm->top); be_incrtop(vm); if (basetype(type) == BE_FUNCTION) { var_setinstance(vm->top, ins); /* push instance on stack as arg 1 */ diff --git a/lib/libesp32/Berry/src/be_vm.c b/lib/libesp32/Berry/src/be_vm.c index 49e20517f..70857ef72 100644 --- a/lib/libesp32/Berry/src/be_vm.c +++ b/lib/libesp32/Berry/src/be_vm.c @@ -267,7 +267,7 @@ bbool be_value2bool(bvm *vm, bvalue *v) static void obj_method(bvm *vm, bvalue *o, bstring *attr, bvalue *dst) { binstance *obj = var_toobj(o); - int type = be_instance_member(vm, obj, attr, dst); + int type = be_instance_member_simple(vm, obj, attr, dst); if (basetype(type) != BE_FUNCTION) { vm_error(vm, "attribute_error", "the '%s' object has no method '%s'",