dos2unix main.c

This commit is contained in:
Josh Holtrop 2014-07-07 21:43:56 -04:00
parent ca12750749
commit 152c48f6b6

78
main.c
View File

@ -1,39 +1,39 @@
#include <stdio.h> #include <stdio.h>
#include "ruby.h" #include "ruby.h"
RUBY_GLOBAL_SETUP RUBY_GLOBAL_SETUP
static VALUE eval(const char * string) static VALUE eval(const char * string)
{ {
int state; int state;
VALUE v = rb_eval_string_protect(string, &state); VALUE v = rb_eval_string_protect(string, &state);
if (state != 0) if (state != 0)
{ {
// fprintf(stderr, "rb_eval_string_protect() returned state %d!\n", state); // fprintf(stderr, "rb_eval_string_protect() returned state %d!\n", state);
VALUE e = rb_errinfo(); VALUE e = rb_errinfo();
VALUE s = rb_funcall(e, rb_intern("message"), 0); VALUE s = rb_funcall(e, rb_intern("message"), 0);
printf("%s\n", StringValueCStr(s)); printf("%s\n", StringValueCStr(s));
rb_set_errinfo(Qnil); rb_set_errinfo(Qnil);
} }
return v; return v;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int _argc = 1; int _argc = 1;
char *_argv[] = {"main"}; char *_argv[] = {"main"};
char **_argv_p = &_argv[0]; char **_argv_p = &_argv[0];
ruby_sysinit(&_argc, &_argv_p); ruby_sysinit(&_argc, &_argv_p);
{ {
RUBY_INIT_STACK; RUBY_INIT_STACK;
ruby_init(); ruby_init();
ruby_init_loadpath(); ruby_init_loadpath();
VALUE v = eval("3 + 8"); VALUE v = eval("3 + 8");
printf("v: %d\n", FIX2INT(v)); printf("v: %d\n", FIX2INT(v));
eval("yoda"); eval("yoda");
eval("File.open('out.txt', 'w') {|fh| fh.puts 'hello!'}"); eval("File.open('out.txt', 'w') {|fh| fh.puts 'hello!'}");
eval("puts 'Hello, World!'"); eval("puts 'Hello, World!'");
ruby_finalize(); ruby_finalize();
} }
return 0; return 0;
} }