Exemplo n.º 1
0
int a2_libsetmeta(struct a2_state* state){
	int args = a2_top(state);
	if(args<2)
		a2_err(state, "the arg error.");
	a2_setmeta(state);
	return 0;
}
Exemplo n.º 2
0
int a2_liblen(struct a2_state* state){
	int args = a2_top(state);
	if(args==0)
		a2_err(state, "the number of args is error.[exp: len(varable)]");
	a2_len(state, 0);
	a2_setvalue(state, 0);
	return 1;
}
Exemplo n.º 3
0
// type
int a2_libtype(struct a2_state* state){
	int args = a2_top(state);
	if(args==0)
		a2_err(state, "the number of args is error.[exp: type(varable)]");
	a2_pushstring(state, (char*)(a2_typeinfo(state, 0)));
	a2_setvalue(state, 0);
	return 1;
}
Exemplo n.º 4
0
int a2_libsystem(struct a2_state* state) {
    int args = a2_top(state);
    if(args==0 || a2_type(state, 0)!=TSTRING)
        a2_err(state, "the arg must string type.");
    const char* str = a2_tostring(state, 0);
    system(str);
    return 0;
}
Exemplo n.º 5
0
int a2_librequire(struct a2_state* state){
	int args = a2_top(state);
	if(args == 0 || a2_type(state, 0)!=TSTRING)
		a2_err(state, "the arg must string type.");
	a2_pushvalue(state, 0);  // set key
	a2_require(state);
	return 1;
}
Exemplo n.º 6
0
// del
int a2_libdel(struct a2_state* state){
	int args = a2_top(state);
	if(args==2 && a2_type(state, 0)==TMAP)
		a2_delmap(state);
	else
		a2_err(state, "exp: del(map, key)");
	return 0;
}
Exemplo n.º 7
0
int a2_libdofile(struct a2_state* state){
	int args = a2_top(state);
	if(args==0 || a2_type(state, 0)!=TSTRING)
		a2_err(state, "the arg must string type.");
	const char* filename = a2_tostring(state, 0);
	int top = a2_top(state);
	a2_loadfile(state, filename);
	return a2_top(state) - top;
}
Exemplo n.º 8
0
int a2_libdostring(struct a2_state* state){
	int args = a2_top(state);
	if(args==0 || a2_type(state, 0)!=TSTRING)
		a2_err(state, "the arg must string type.");
	const char* str = a2_tostring(state, 0);
	int top = a2_top(state);
	a2_dostring(state, str, strlen(str));
	return a2_top(state) - top;
}
Exemplo n.º 9
0
int a2_libdostring(struct a2_state* state){
	int args = a2_top(state);
	if(args==0 || a2_type(state, 0)!=TSTRING)
		a2_err(state, "the arg must string type.");
	const char* str = a2_tostring(state, 0);
	if(a2_dostring(state, str, strlen(str))){
		printf("%s\n", a2_tostring(state, a2_top(state)-1));
	}
	return 0;
}
Exemplo n.º 10
0
// add
int a2_libadd(struct a2_state* state){
	int args = a2_top(state);
	if(args<2)
		a2_err(state, "the number of args is error.");
	switch(a2_type(state, 0)){
		case TARRAY:
			if(args!=2)
				a2_err(state, "the number of args is error at array add.[exp: add(array, value)]");
			a2_addarray(state);
			break;
		case TMAP:
			if(args!=3)
				a2_err(state, "the number of args is error at map set.[exp: add(map, key value)]");
			a2_setmap(state);
			break;
		default:
			a2_err(state, "the varable is not container.");
	}
	return 0;
}
Exemplo n.º 11
0
A2_API void a2_setmeta(struct a2_state* state){
	int top = a2_top(state)-1;
	struct a2_obj* m = a2_getcstack(state->env_p, top);
	struct a2_obj* v = a2_getcstack(state->env_p, top-1);

	if(obj_t(v)!=A2_TMAP || obj_t(m)!=A2_TMAP)
		a2_err(state, "the value and meta should map type.");

	a2_gc_setmeta(obj_vX(v, obj), obj_vX(m, obj));
	a2_topset(state, top-1);
}