mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-16 15:26:29 +00:00
Berry classof
extended to class methods (#21615)
This commit is contained in:
parent
87148ae0c1
commit
bd47d99ceb
@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
## [14.1.0.2]
|
## [14.1.0.2]
|
||||||
### Added
|
### Added
|
||||||
|
- Berry `classof` extended to class methods
|
||||||
|
|
||||||
### Breaking Changed
|
### Breaking Changed
|
||||||
|
|
||||||
|
@ -544,6 +544,22 @@ BERRY_API bbool be_classof(bvm *vm, int index)
|
|||||||
binstance *ins = var_toobj(v);
|
binstance *ins = var_toobj(v);
|
||||||
var_setclass(top, be_instance_class(ins));
|
var_setclass(top, be_instance_class(ins));
|
||||||
return btrue;
|
return btrue;
|
||||||
|
} else if (var_isclosure(v)) {
|
||||||
|
bclosure *cl = var_toobj(v);
|
||||||
|
bproto *pr = cl->proto;
|
||||||
|
if (pr != NULL) {
|
||||||
|
bclass *cla;
|
||||||
|
if (pr->nproto > 0) {
|
||||||
|
cla = (bclass*) pr->ptab[pr->nproto];
|
||||||
|
} else {
|
||||||
|
cla = (bclass*) pr->ptab;
|
||||||
|
}
|
||||||
|
if (cla && var_basetype(cla) == BE_CLASS) {
|
||||||
|
bvalue *top = be_incrtop(vm);
|
||||||
|
var_setclass(top, cla);
|
||||||
|
return btrue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return bfalse;
|
return bfalse;
|
||||||
}
|
}
|
||||||
|
@ -57,4 +57,19 @@ c4 = Test_class()
|
|||||||
assert(type(c4.c) == 'class')
|
assert(type(c4.c) == 'class')
|
||||||
c5 = c4.c()
|
c5 = c4.c()
|
||||||
assert(type(c5) == 'instance')
|
assert(type(c5) == 'instance')
|
||||||
assert(classname(c5) == 'map')
|
assert(classname(c5) == 'map')
|
||||||
|
|
||||||
|
#- classof now gets back the class of Berry methods -#
|
||||||
|
class A
|
||||||
|
def f() end
|
||||||
|
static def g() end
|
||||||
|
end
|
||||||
|
class B : A
|
||||||
|
def h() end
|
||||||
|
end
|
||||||
|
assert(classof(A.f) == A)
|
||||||
|
assert(classof(A.g) == A)
|
||||||
|
assert(classof(B.h) == B)
|
||||||
|
#- returns nil if native function of not in class -#
|
||||||
|
assert(classof(int) == nil)
|
||||||
|
assert(classof(def () end) == nil)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user