change native function num()

num now returns nil if the argument is not a number or numerable string.
This commit is contained in:
ValKmjolnir 2022-01-27 21:41:06 +08:00
parent 05ab4640da
commit 0a407437a4
2 changed files with 7 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# __Nasal Script Language__
# __Nasal Scripting Language__
```C++
__ _

View File

@ -358,9 +358,14 @@ nasal_ref builtin_int(std::vector<nasal_ref>& local,nasal_gc& gc)
nasal_ref builtin_num(std::vector<nasal_ref>& 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<nasal_ref>& local,nasal_gc& gc)
{