Nasal-Interpreter/lib.nas

143 lines
2.6 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
{
return __builtin_std_cout(elems);
2020-10-23 14:53:04 +08:00
};
var println=func(elems...)
2021-02-12 22:27:41 +08:00
{
__builtin_std_cout(elems);
return print('\n');
2021-02-12 22:27:41 +08:00
}
var append=func(vec,elems...)
2020-10-23 14:53:04 +08:00
{
return __builtin_push_back(vec,elems);
2020-10-23 14:53:04 +08:00
}
var setsize=func(vec,size)
2020-10-23 14:53:04 +08:00
{
return __builtin_set_size(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
{
return __builtin_get_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
{
return __builtin_pop_back(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-03-27 01:08:05 +08:00
return __builtin_get_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); },
atan2: func(x,y){return __builtin_atan2(x,y);}
2020-10-23 14:53:04 +08:00
};
2021-04-02 22:19:29 +08:00
var D2R=math.pi/180;