correct initialization of Ruby interpreter
This commit is contained in:
parent
583da83cd3
commit
dd221019cc
30
main.c
30
main.c
@ -1,10 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include "ruby.h"
|
||||
|
||||
RUBY_GLOBAL_SETUP
|
||||
|
||||
static VALUE eval(const char * string)
|
||||
{
|
||||
int state;
|
||||
VALUE v = rb_eval_string_protect(string, &state);
|
||||
if (state != 0)
|
||||
{
|
||||
fprintf(stderr, "rb_eval_string_protect() returned state %d!\n", state);
|
||||
rb_set_errinfo(Qnil);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ruby_init();
|
||||
ruby_init_loadpath();
|
||||
VALUE v = rb_eval_string("3 + 8");
|
||||
printf("v: %d\n", FIX2INT(v));
|
||||
ruby_sysinit(&argc, &argv);
|
||||
{
|
||||
RUBY_INIT_STACK;
|
||||
ruby_init();
|
||||
ruby_init_loadpath();
|
||||
VALUE v = eval("3 + 8");
|
||||
printf("v: %d\n", FIX2INT(v));
|
||||
eval("File.open('out.txt', 'w') {|fh| fh.puts 'hello!'}");
|
||||
eval("puts 'Hello, World!'");
|
||||
ruby_finalize();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user