From: Jérémie Astor Date: Wed, 15 Dec 2021 15:59:41 +0000 (+0100) Subject: :art: Put atoi and atof in string class X-Git-Tag: nightly~392 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=20b305007d3a5944e3ec6a9ef4b059217041cac7;p=gwion.git :art: Put atoi and atof in string class --- diff --git a/src/lib/string.c b/src/lib/string.c index 60559940..7d4c4138 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -397,6 +397,26 @@ static SFUN(string_load) { *(M_Object*)RETURN = new_string(shred->info->vm->gwion, c); } +static MFUN(string_atoi) { + const M_Object obj = *(M_Object*)MEM(0); + const m_str str = STRING(obj); + *(m_int*)RETURN = atoi(str); +} + +static MFUN(string_atof) { + const M_Object obj = *(M_Object*)MEM(0); + const m_str str = STRING(obj); + *(m_float*)RETURN = (m_float)atof(str); +} +/* +static MFUN(string_atoi2) { + const M_Object obj = *(M_Object*)MEM(0); + const m_str str = STRING(obj); + char *endptr; + *(m_int*)RETURN = strtol(str, &endptr, 10); + **(m_uint**)MEM(SZ_INT) = endptr - str; +} +*/ GWION_IMPORT(string) { const Type t_string = gwi_class_ini(gwi, "string", NULL); gwi->gwion->type[et_string] = t_string; // use func @@ -496,6 +516,16 @@ GWION_IMPORT(string) { gwi_func_arg(gwi, "string", "path"); GWI_BB(gwi_func_end(gwi, string_load, ae_flag_static)) + gwi_func_ini(gwi, "int", "atoi"); + GWI_BB(gwi_func_end(gwi, string_atoi, ae_flag_none)) + + gwi_func_ini(gwi, "float", "atof"); + GWI_BB(gwi_func_end(gwi, string_atof, ae_flag_none)) +/* + gwi_func_ini(gwi, "int", "atoi"); + gwi_func_arg(gwi, "Ref:[int]", "idx"); + GWI_BB(gwi_func_end(gwi, string_atoi2, ae_flag_none)) +*/ GWI_BB(gwi_class_end(gwi)) GWI_BB(gwi_oper_ini(gwi, "string", "string", "bool"))