-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstage9.pl
54 lines (47 loc) · 1.3 KB
/
stage9.pl
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
use Inline C;
use Inline C => config => libs => '-lruby-2.1',
clean_after_build => 0,
inc => '-I/usr/include/ruby-2.1.0 -I/usr/include/x86_64-linux-gnu/ruby-2.1.0';
sub blep {
my ($foo) = @_;
print "Stage 9: ${foo}\n";
my $bar = perl_do_the_thing("./stage10.rb", $foo);
print "Return value[9]: ${bar}\n";
return $bar;
}
__END__
__C__
#include <ruby.h>
#include <string.h>
#include <errno.h>
VALUE funcall_wrapper(VALUE actors) {
return rb_funcall(rb_mKernel, rb_intern("blep"), 1, actors);
}
void print_rb_exc(void) {
VALUE exception = rb_errinfo();
rb_set_errinfo(Qnil);
if (RTEST(exception)) {
rb_warn("Ruby exception: %"PRIsVALUE"", exception);
}
}
char *perl_do_the_thing(char *fname, char *arg1) {
int state = 0;
if (ruby_setup()) {
return "Ruby setup failed.";
}
ruby_script("stage9");
ruby_init_loadpath();
rb_load_protect(rb_str_new_cstr(fname), 0, &state);
if (state) {
print_rb_exc();
return "Ruby load_protect failed.";
}
VALUE rbrv = rb_protect(funcall_wrapper, rb_str_new_cstr(arg1), &state);
if (state) {
print_rb_exc();
return "Ruby funcall failed.";
}
char *rv = strdup(StringValueCStr(rbrv));
ruby_cleanup(0);
return rv;
}