File: extltest.c

package info (click to toggle)
notion 3%2B2014010901-1
  • links: PTS, VCS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd
  • size: 4,940 kB
  • ctags: 6,104
  • sloc: ansic: 46,870; sh: 2,008; makefile: 598; perl: 270
file content (60 lines) | stat: -rw-r--r-- 1,273 bytes parent folder | download | duplicates (2)
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
60
#include "../luaextl.c"
#include "../readconfig.c"

static const char tostringstr[]=
    "local arg = {...}\n"
    "print('first arg is a ' .. type(arg[1]))\n"
    "local basis = arg[1]()\n"
    "local result\n"
    "print('first arg returned a ' .. type(basis))\n"
    "if type(basis)=='string' then\n"
    "    result = string.format('%q', basis)\n"
    "else\n"
    "    result = tostring(basis)\n"
    "end\n"
    "print('result is a ' .. type(result))\n"
    "print('result is ' .. result)\n"
    "return result\n";

int test_tostring()
{
    ExtlFn tostringfn;
    ExtlFn fn;
    ErrorLog el;
    char *retstr=NULL;

    errorlog_begin(&el);

    if(!extl_loadstring(tostringstr, &tostringfn))
        return 1;

    if(!extl_loadstring("print('testing\\n'); return 'test'", &fn))
        return 2;
fprintf(stderr, "Calling extl_call...\n");
    if(!extl_call(tostringfn, "f", "s", fn, &retstr))
        return 3;

    if (retstr == NULL)
        return 4;
 
    if(strcmp("\"test\"", retstr) != 0){
        fprintf(stderr, "Result was '%s' instead of 'test'", retstr);
        return 5;
    }

    return 0;
}


int main()
{
    int result = 0;   

    extl_init();

    result += test_tostring();

    fprintf(stderr, "Result: %d\n", result);

    return result;
}