How do you read the value of a bool?
MP_OBJ_IS_TYPE(o, &mp_type_bool)
But then how do you get the value of a bool?
You cannot cast it to mp_obj_bool_t because that is not in a header.
[SOLVED]mp_obj_bool_t is private which means you cannot read value of a bool
[SOLVED]mp_obj_bool_t is private which means you cannot read value of a bool
Last edited by jickster on Mon Feb 26, 2018 6:50 pm, edited 1 time in total.
Re: mp_obj_bool_t is private which means you cannot read value of a bool
https://github.com/micropython/micropython/issues/3641
In general the way to decide truthness is to use mp_obj_is_true(o). This will cover all cases in Python where you are allowed to use an object in place of a bool (eg if you pass 0 or 1).
There's also mp_obj_is_integer(o) which can be used to tell if an object is an integer or bool.
If it's really important to distinguish False and True from 0 and 1 then use the expression: (MP_OBJ_TO_PTR(o) == mp_const_true).