mirror of https://github.com/arendst/Tasmota.git
Berry improved booleans
This commit is contained in:
parent
11689409fc
commit
147bbc133e
|
@ -281,6 +281,12 @@ bbool be_value2bool(bvm *vm, bvalue *v)
|
|||
return val2bool(v->v.i);
|
||||
case BE_REAL:
|
||||
return val2bool(v->v.r);
|
||||
case BE_STRING:
|
||||
return str_len(var_tostr(v)) != 0;
|
||||
case BE_COMPTR:
|
||||
return var_toobj(v) != NULL;
|
||||
case BE_COMOBJ:
|
||||
return ((bcommomobj*)var_toobj(v))->data != NULL;
|
||||
case BE_INSTANCE:
|
||||
return obj2bool(vm, v);
|
||||
default:
|
||||
|
|
|
@ -33,7 +33,11 @@ assert(bool(nil) == false)
|
|||
|
||||
assert(bool(-1) == true)
|
||||
assert(bool(3.5) == true)
|
||||
assert(bool('') == true)
|
||||
assert(bool('') == false) # changed behavior
|
||||
assert(bool('a') == true)
|
||||
assert(bool(list) == true)
|
||||
assert(bool(list()) == true)
|
||||
|
||||
import introspect
|
||||
assert(bool(introspect.toptr(0x1000)) == true)
|
||||
assert(bool(introspect.toptr(0)) == false)
|
||||
|
|
Loading…
Reference in New Issue