bug fixed & add systime, finished vecindex
This commit is contained in:
parent
aed5e27409
commit
399b2f0ce9
6
lib.nas
6
lib.nas
|
@ -211,7 +211,7 @@ var isnum=func(x){
|
||||||
|
|
||||||
var isscalar=func(s){
|
var isscalar=func(s){
|
||||||
var t=typeof(s);
|
var t=typeof(s);
|
||||||
return t=="num" or t=="str";
|
return (t=="num" or t=="str")?1:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var isstr=func(s){
|
var isstr=func(s){
|
||||||
|
@ -223,7 +223,9 @@ var isvec=func(v){
|
||||||
}
|
}
|
||||||
|
|
||||||
var vecindex=func(vec,val){
|
var vecindex=func(vec,val){
|
||||||
# unfinished
|
forindex(var i;vec)
|
||||||
|
if(val==vec[i])
|
||||||
|
return i;
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -521,7 +521,8 @@ inline void nasal_vm::opr_eq()
|
||||||
gc.top[0]=one;
|
gc.top[0]=one;
|
||||||
else if(val1.type==vm_str && val2.type==vm_str)
|
else if(val1.type==vm_str && val2.type==vm_str)
|
||||||
gc.top[0]=(val1.str()==val2.str())?one:zero;
|
gc.top[0]=(val1.str()==val2.str())?one:zero;
|
||||||
else if(val1.type==vm_num || val2.type==vm_num)
|
else if((val1.type==vm_num || val2.type==vm_num)
|
||||||
|
&& val1.type!=vm_nil && val2.type!=vm_nil)
|
||||||
gc.top[0]=(val1.to_number()==val2.to_number())?one:zero;
|
gc.top[0]=(val1.to_number()==val2.to_number())?one:zero;
|
||||||
else
|
else
|
||||||
gc.top[0]=(val1==val2)?one:zero;
|
gc.top[0]=(val1==val2)?one:zero;
|
||||||
|
@ -534,7 +535,8 @@ inline void nasal_vm::opr_neq()
|
||||||
gc.top[0]=zero;
|
gc.top[0]=zero;
|
||||||
else if(val1.type==vm_str && val2.type==vm_str)
|
else if(val1.type==vm_str && val2.type==vm_str)
|
||||||
gc.top[0]=(val1.str()!=val2.str())?one:zero;
|
gc.top[0]=(val1.str()!=val2.str())?one:zero;
|
||||||
else if(val1.type==vm_num || val2.type==vm_num)
|
else if((val1.type==vm_num || val2.type==vm_num)
|
||||||
|
&& val1.type!=vm_nil && val2.type!=vm_nil)
|
||||||
gc.top[0]=(val1.to_number()!=val2.to_number())?one:zero;
|
gc.top[0]=(val1.to_number()!=val2.to_number())?one:zero;
|
||||||
else
|
else
|
||||||
gc.top[0]=(val1!=val2)?one:zero;
|
gc.top[0]=(val1!=val2)?one:zero;
|
||||||
|
|
|
@ -211,7 +211,7 @@ var isnum=func(x){
|
||||||
|
|
||||||
var isscalar=func(s){
|
var isscalar=func(s){
|
||||||
var t=typeof(s);
|
var t=typeof(s);
|
||||||
return t=="num" or t=="str";
|
return (t=="num" or t=="str")?1:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var isstr=func(s){
|
var isstr=func(s){
|
||||||
|
@ -223,7 +223,9 @@ var isvec=func(v){
|
||||||
}
|
}
|
||||||
|
|
||||||
var vecindex=func(vec,val){
|
var vecindex=func(vec,val){
|
||||||
# unfinished
|
forindex(var i;vec)
|
||||||
|
if(val==vec[i])
|
||||||
|
return i;
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,3 +150,20 @@ f1() or f2();
|
||||||
# this means that when using 'or' or 'and',
|
# this means that when using 'or' or 'and',
|
||||||
# if the result is clear when calculating,
|
# if the result is clear when calculating,
|
||||||
# objects behind will not be calculated
|
# objects behind will not be calculated
|
||||||
|
|
||||||
|
print(
|
||||||
|
subvec([0,1,2,3],2),'\n',
|
||||||
|
subvec([0,1,2,3],2,1),'\n',
|
||||||
|
abs(1),'\n',
|
||||||
|
abs(-1),'\n',
|
||||||
|
systime(),'\n',
|
||||||
|
isfunc(func{}),' ',isfunc([]),'\n',
|
||||||
|
ishash({}),' ',ishash([]),'\n',
|
||||||
|
isint(114.514),' ',isint(114514),'\n',
|
||||||
|
isnum("0xaa55"),' ',isnum("?"),'\n',
|
||||||
|
isscalar(0.618),' ',isscalar("hello"),' ',isscalar([]),'\n',
|
||||||
|
isstr("hello"),' ',isstr(func{}),'\n',
|
||||||
|
isvec([]),' ',isvec("[]"),'\n',
|
||||||
|
vecindex([0,1,2,3,4],1),'\n',
|
||||||
|
vecindex(["apple","banana"],"apple")!=nil,'\n'
|
||||||
|
);
|
Loading…
Reference in New Issue