-
Notifications
You must be signed in to change notification settings - Fork 1
/
return.c
58 lines (52 loc) · 1.15 KB
/
return.c
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
#include <stdio.h>
#include <mruby.h>
#include <mruby/compile.h>
int main (int argc, const char **argv) {
FILE *f;
mrb_value val;
int i;
mrb_state *mrb = mrb_open();
if (!mrb) return 1;
if (!(f = fopen("return.rb", "r"))) return 1;
mrb_load_file(mrb, f);
fclose(f);
val = mrb_funcall(mrb, mrb_top_self(mrb), "return_int", 0);
switch (mrb_type(val)) {
case MRB_TT_FIXNUM:
i = mrb_int(mrb, val);
printf("Returned a fixnum: %i\n", i);
break;
case MRB_TT_ARRAY:
printf("Returned an array\n");
break;
default:
printf("Unlisted return type\n");
break;
}
val = mrb_funcall(mrb, mrb_top_self(mrb), "return_array", 0);
switch (mrb_type(val)) {
case MRB_TT_FIXNUM:
printf("Returned a fixnum\n");
break;
case MRB_TT_ARRAY:
printf("Returned an array\n");
break;
default:
printf("Unlisted return type\n");
break;
}
val = mrb_funcall(mrb, mrb_top_self(mrb), "return_nil", 0);
switch (mrb_type(val)) {
case MRB_TT_FIXNUM:
printf("Returned a fixnum\n");
break;
case MRB_TT_ARRAY:
printf("Returned an array\n");
break;
default:
printf("Unlisted return type\n");
break;
}
mrb_close(mrb);
return 0;
}