File: fgw_string.c

package info (click to toggle)
fungw 1.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,268 kB
  • sloc: ansic: 24,257; makefile: 500; sh: 32; awk: 9; perl: 8; tcl: 7; javascript: 7; ruby: 7; python: 6
file content (59 lines) | stat: -rw-r--r-- 1,313 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdlib.h>
#include <libfungw/fungw.h>
#include <libfungwbind/c/fungw_c.h>

static const char *dom_string = "c-string";

fgw_error_t fgwc_malloc(fgw_arg_t *res, int argc, fgw_arg_t *argv)
{
	FGW_DECL_CTX;
	FGW_ARGC_REQ_MATCH(1);
	FGW_ARG_CONV(&argv[1], FGW_SIZE_T);
	fgw_ptr_reg(ctx, res, dom_string, FGW_VOID, malloc(argv[0].val.nat_size_t));
	return FGW_SUCCESS;
}


fgw_error_t fgwc_free(fgw_arg_t *res, int argc, fgw_arg_t *argv)
{
	FGW_DECL_CTX;
	FGW_ARGC_REQ_MATCH(1);
	FGW_ARG_CONV(&argv[1], FGW_PTR | FGW_VOID);
	res->type = FGW_VOID;
	fgw_ptr_unreg(ctx, &argv[1], dom_string);
	free(argv[1].val.ptr_void);
	return FGW_SUCCESS;
}

int *atoi_ucc = NULL;
fgw_error_t fgwc_atoi(fgw_arg_t *res, int argc, fgw_arg_t *argv)
{
	FGW_DECL_CTX;
	FGW_ARGC_REQ_MATCH(1);
	FGW_ARG_CONV(&argv[1], FGW_STR);
	atoi_ucc = argv[0].val.argv0.user_call_ctx;
	res->val.nat_int = atoi(argv[1].val.str);
	res->type = FGW_INT;
	return FGW_SUCCESS;
}

static int on_load(fgw_obj_t *obj, const char *filename, const char *opts)
{
	fgw_func_reg(obj, "atoi",   fgwc_atoi);
	fgw_func_reg(obj, "malloc", fgwc_malloc);
	fgw_func_reg(obj, "free",   fgwc_free);
	return 0;
}


static const fgw_eng_t fgw_string_eng = {
	"string",
	fgws_c_call_script,
	NULL,
	on_load
};

void string_init(void)
{
	fgw_eng_reg(&fgw_string_eng);
}