added tonumber() and tostring() to base lib

This commit is contained in:
2021-01-13 14:13:55 -06:00
parent 8cd0112c48
commit e995bb75fb
5 changed files with 56 additions and 1 deletions

View File

@@ -461,6 +461,17 @@ CObjString *cosmoO_toString(CState *state, CObj *obj) {
}
}
cosmo_Number cosmoO_toNumber(CState *state, CObj *obj) {
switch (obj->type) {
case COBJ_STRING: {
CObjString *str = (CObjString*)obj;
return strtod(str->str, NULL);
}
default: // maybe in the future throw an error?
return 0;
}
}
void printObject(CObj *o) {
switch (o->type) {
case COBJ_STRING: {