From 0a407437a42409fd53f9193dca6076df0f3d6e7c Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Thu, 27 Jan 2022 21:41:06 +0800 Subject: [PATCH] change native function num() num now returns nil if the argument is not a number or numerable string. --- README.md | 2 +- nasal_builtin.h | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 729fc27..c3b3696 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# __Nasal Script Language__ +# __Nasal Scripting Language__ ```C++ __ _ diff --git a/nasal_builtin.h b/nasal_builtin.h index 0dc6602..dbb2258 100644 --- a/nasal_builtin.h +++ b/nasal_builtin.h @@ -358,9 +358,14 @@ nasal_ref builtin_int(std::vector& local,nasal_gc& gc) nasal_ref builtin_num(std::vector& local,nasal_gc& gc) { nasal_ref val=local[1]; + if(val.type==vm_num) + return val; if(val.type!=vm_str) return gc.nil; - return {vm_num,val.to_number()}; + double res=val.to_number(); + if(std::isnan(res)) + return gc.nil; + return {vm_num,res}; } nasal_ref builtin_pop(std::vector& local,nasal_gc& gc) {