<stdbool.h> type conversion
donderom opened this issue · 4 comments
Is there any way to add type conversions between builtin and custom data types?
For example I'm using byte for mapping bool but it would be nice to specify a conversion to/from boolean (by type class?) in the mapping.
Sorry, it's not currently possible to do this. In order to do this I need to allow for transform types (types that have one backing in C, but another in Scala). It'd be something similar to alias types that exist currently.
It would be nice to be able to define a TypeDescriptor
for some custom type but at the same it's been only boolean
I've faced issues with so far.
This can now be done by defining a Transform:
given Transform[Boolean, Int](
i => if i != 0 then true else false,
b => if b then 1 else 0
)
I've also added types CBool
and CBoolShort
, for char width and short width primitives that should be read as booleans.
All my tests for bools pass, thanks a lot! 👍🏼