From 47a103f7ea4b7125bb175c2683e791d300b283fe Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 9 Mar 2022 09:58:10 +0000 Subject: [PATCH] Nasal: add str() helper to force a type to be a string Calls existing naStringValue internally. --- simgear/nasal/lib.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/simgear/nasal/lib.c b/simgear/nasal/lib.c index dc9d5a47..f0006fc8 100644 --- a/simgear/nasal/lib.c +++ b/simgear/nasal/lib.c @@ -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 },