Releasing version 3-2015061300
[notion.git] / libextl / test / extltest.c
blobb5d0f84ba25cb2cec6531a55b840155f229b31f0
1 #include "../luaextl.c"
2 #include "../readconfig.c"
4 static const char tostringstr[]=
5 "local arg = {...}\n"
6 "print('first arg is a ' .. type(arg[1]))\n"
7 "local basis = arg[1]()\n"
8 "local result\n"
9 "print('first arg returned a ' .. type(basis))\n"
10 "if type(basis)=='string' then\n"
11 " result = string.format('%q', basis)\n"
12 "else\n"
13 " result = tostring(basis)\n"
14 "end\n"
15 "print('result is a ' .. type(result))\n"
16 "print('result is ' .. result)\n"
17 "return result\n";
19 int test_tostring()
21 ExtlFn tostringfn;
22 ExtlFn fn;
23 ErrorLog el;
24 char *retstr=NULL;
26 errorlog_begin(&el);
28 if(!extl_loadstring(tostringstr, &tostringfn))
29 return 1;
31 if(!extl_loadstring("print('testing\\n'); return 'test'", &fn))
32 return 2;
33 fprintf(stderr, "Calling extl_call...\n");
34 if(!extl_call(tostringfn, "f", "s", fn, &retstr))
35 return 3;
37 if (retstr == NULL)
38 return 4;
40 if(strcmp("\"test\"", retstr) != 0){
41 fprintf(stderr, "Result was '%s' instead of 'test'", retstr);
42 return 5;
45 return 0;
49 int main()
51 int result = 0;
53 extl_init();
55 result += test_tostring();
57 fprintf(stderr, "Result: %d\n", result);
59 return result;