Nasal-Interpreter/lib.nas

162 lines
3.0 KiB
Plaintext
Raw Normal View History

2020-10-23 14:53:04 +08:00
var import=func(filename)
{
return __builtin_import(filename);
2020-10-23 14:53:04 +08:00
}
var print=func(elems...)
2020-10-23 14:53:04 +08:00
{
2021-06-19 00:32:10 +08:00
return __builtin_print(elems);
2020-10-23 14:53:04 +08:00
};
var println=func(elems...)
2021-02-12 22:27:41 +08:00
{
2021-06-19 00:32:10 +08:00
__builtin_print(elems);
elems=['\n'];
return __builtin_print(elems);
2021-02-12 22:27:41 +08:00
}
var append=func(vec,elems...)
2020-10-23 14:53:04 +08:00
{
2021-06-19 00:32:10 +08:00
return __builtin_append(vec,elems);
2020-10-23 14:53:04 +08:00
}
var setsize=func(vec,size)
2020-10-23 14:53:04 +08:00
{
2021-06-19 00:32:10 +08:00
return __builtin_setsize(vec,size);
2020-10-23 14:53:04 +08:00
}
var system=func(str)
{
return __builtin_system(str);
2020-10-23 14:53:04 +08:00
}
var input=func()
{
2021-03-27 01:08:05 +08:00
return __builtin_input();
2020-10-23 14:53:04 +08:00
}
var sleep=func(duration)
{
return __builtin_sleep(duration);
2020-10-23 14:53:04 +08:00
}
var split=func(deli,str)
2020-10-23 14:53:04 +08:00
{
return __builtin_split(deli,str);
2020-10-23 14:53:04 +08:00
}
var rand=func(seed=nil)
{
2021-03-27 01:08:05 +08:00
return __builtin_rand(seed);
2020-10-23 14:53:04 +08:00
}
var id=func(object)
2020-10-23 14:53:04 +08:00
{
2021-06-19 00:32:10 +08:00
return __builtin_id(object);
2020-10-23 14:53:04 +08:00
}
var int=func(val)
2020-10-23 14:53:04 +08:00
{
return __builtin_int(val);
2020-10-23 14:53:04 +08:00
}
var num=func(val)
2020-10-23 14:53:04 +08:00
{
return __builtin_num(val);
2020-10-23 14:53:04 +08:00
}
var pop=func(vec)
2020-10-23 14:53:04 +08:00
{
2021-06-19 00:32:10 +08:00
return __builtin_pop(vec);
2020-10-23 14:53:04 +08:00
}
var str=func(num)
2020-10-23 14:53:04 +08:00
{
return __builtin_str(num);
2020-10-23 14:53:04 +08:00
}
var size=func(object)
{
2021-03-27 01:08:05 +08:00
return __builtin_size(object);
2020-10-23 14:53:04 +08:00
}
var contains=func(hash,key)
{
2021-03-27 01:08:05 +08:00
return __builtin_contains(hash,key);
2020-10-23 14:53:04 +08:00
}
var delete=func(hash,key)
{
return __builtin_delete(hash,key);
2020-10-23 14:53:04 +08:00
}
var keys=func(hash)
{
2021-06-19 00:32:10 +08:00
return __builtin_keys(hash);
2020-10-23 14:53:04 +08:00
}
var time=func(begin_time)
{
2021-03-27 01:08:05 +08:00
return __builtin_time(begin_time);
2020-10-23 14:53:04 +08:00
}
var die=func(str)
{
return __builtin_die(str);
2020-10-23 14:53:04 +08:00
}
2020-11-02 12:24:12 +08:00
var typeof=func(object)
2020-10-23 14:53:04 +08:00
{
2021-03-27 01:08:05 +08:00
return __builtin_type(object);
2020-10-23 14:53:04 +08:00
}
var substr=func(str,begin,len)
2020-10-25 22:15:49 +08:00
{
return __builtin_substr(str,begin,len);
2020-10-25 22:15:49 +08:00
}
var streq=func(a,b)
{
2021-03-27 01:08:05 +08:00
return __builtin_streq(a,b);
}
var left=func(str,len)
{
return __builtin_left(str,len);
}
var right=func(str,len)
{
return __builtin_right(str,len);
}
var cmp=func(a,b)
{
2021-03-27 01:08:05 +08:00
return __builtin_cmp(a,b);
}
var chr=func(code)
{
2021-03-27 01:08:05 +08:00
return __builtin_chr(code);
}
2020-10-23 14:53:04 +08:00
var io=
{
fin: func(filename){return __builtin_fin(filename);},
fout:func(filename,str){return __builtin_fout(filename,str);}
2020-10-23 14:53:04 +08:00
};
var bits=
{
2021-03-27 01:08:05 +08:00
bitxor: func(a,b){return __builtin_xor(a,b); },
bitand: func(a,b){return __builtin_and(a,b); },
bitor: func(a,b){return __builtin_or(a,b); },
bitnand: func(a,b){return __builtin_nand(a,b);},
bitnot: func(a) {return __builtin_not(a); }
2020-10-23 14:53:04 +08:00
};
var math=
{
2021-02-12 22:27:41 +08:00
e: 2.7182818284590452354,
pi: 3.14159265358979323846264338327950288,
2021-03-27 01:08:05 +08:00
sin: func(x) {return __builtin_sin(x); },
cos: func(x) {return __builtin_cos(x); },
tan: func(x) {return __builtin_tan(x); },
exp: func(x) {return __builtin_exp(x); },
ln: func(x) {return __builtin_ln(x); },
sqrt: func(x) {return __builtin_sqrt(x); },
2021-08-27 17:43:01 +08:00
atan2: func(x,y){return __builtin_atan2(x,y);},
2021-09-01 19:15:32 +08:00
inf: 1/0,
2021-09-25 23:25:31 +08:00
nan: 0/0,
2021-08-27 17:43:01 +08:00
isnan: func(x) {return __builtin_isnan(x); }
2020-10-23 14:53:04 +08:00
};
2021-04-02 22:19:29 +08:00
2021-09-02 19:10:49 +08:00
var D2R=math.pi/180;
var FPS2KT=0.5925;
var FT2M=0.3048;
var GAL2L=3.7854;
var IN2M=0.0254;
var KG2LB=2.2046;
var KT2FPS=1.6878;
var KT2MPS=0.5144;
var L2GAL=0.2642;
var LB2KG=0.4536;
var M2FT=3.2808;
var M2IN=39.3701;
var M2NM=0.00054;
var MPS2KT=1.9438;
var NM2M=1852;
var R2D=180/math.pi;