mirror of
https://github.com/CPunch/Cosmo.git
synced 2026-01-02 22:00:17 +00:00
added tonumber() and tostring() to base lib
This commit is contained in:
11
src/cobj.c
11
src/cobj.c
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user