Nasal: add str() helper to force a type to be a string

Calls existing naStringValue internally.
This commit is contained in:
James Turner
2022-03-09 09:58:10 +00:00
parent 6bbf7ed109
commit 47a103f7ea

View File

@@ -148,6 +148,14 @@ static naRef f_cmp(naContext c, naRef me, int argc, naRef* args)
return naNum(alen == blen ? 0 : (alen < blen ? -1 : 1));
}
static naRef f_str(naContext c, naRef me, int argc, naRef* args)
{
if (argc < 1)
ARGERR();
return naStringValue(c, args[0]);
}
static naRef f_substr(naContext c, naRef me, int argc, naRef* args)
{
int start, len, srclen;
@@ -752,6 +760,7 @@ static naCFuncItem funcs[] = {
{ "delete", f_delete },
{ "int", f_int },
{ "num", f_num },
{ "str", f_str },
{ "streq", f_streq },
{ "cmp", f_cmp },
{ "substr", f_substr },