blob: 578cabeacce7ae18bd570f16ab83e0b99506a34e (
plain)
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
|
#include <parser.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void test(interpreter *it)
{
char *s = igetarg_string(it, 0);
if (s == 0)
s = "(null)";
printf("%s\n", s);
}
void quit(interpreter *it)
{
(void)it;
exit(0);
}
int main()
{
interpreter interp;
iinit(&interp);
inew_integer(&interp, "answer", 42);
inew_cfunc(&interp, "put", test);
inew_cfunc(&interp, "exit", quit);
char *line = 0;
unsigned int size;
int result;
while (1) {
getline(&line, &size, stdin);
*strchr(line, '\n') = '\0';
result = idoline(&interp, line);
if (result != 0)
printf("Error: %d\n", result);
}
return 0;
}
|