Berry improved booleans

This commit is contained in:
Stephan Hadinger 2022-06-24 23:17:33 +02:00
parent 11689409fc
commit 147bbc133e
2 changed files with 11 additions and 1 deletions

View File

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

View File

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