dos2unix main.c
This commit is contained in:
parent
ca12750749
commit
152c48f6b6
78
main.c
78
main.c
@ -1,39 +1,39 @@
|
||||
#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);
|
||||
VALUE e = rb_errinfo();
|
||||
VALUE s = rb_funcall(e, rb_intern("message"), 0);
|
||||
printf("%s\n", StringValueCStr(s));
|
||||
rb_set_errinfo(Qnil);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int _argc = 1;
|
||||
char *_argv[] = {"main"};
|
||||
char **_argv_p = &_argv[0];
|
||||
ruby_sysinit(&_argc, &_argv_p);
|
||||
{
|
||||
RUBY_INIT_STACK;
|
||||
ruby_init();
|
||||
ruby_init_loadpath();
|
||||
VALUE v = eval("3 + 8");
|
||||
printf("v: %d\n", FIX2INT(v));
|
||||
eval("yoda");
|
||||
eval("File.open('out.txt', 'w') {|fh| fh.puts 'hello!'}");
|
||||
eval("puts 'Hello, World!'");
|
||||
ruby_finalize();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#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);
|
||||
VALUE e = rb_errinfo();
|
||||
VALUE s = rb_funcall(e, rb_intern("message"), 0);
|
||||
printf("%s\n", StringValueCStr(s));
|
||||
rb_set_errinfo(Qnil);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int _argc = 1;
|
||||
char *_argv[] = {"main"};
|
||||
char **_argv_p = &_argv[0];
|
||||
ruby_sysinit(&_argc, &_argv_p);
|
||||
{
|
||||
RUBY_INIT_STACK;
|
||||
ruby_init();
|
||||
ruby_init_loadpath();
|
||||
VALUE v = eval("3 + 8");
|
||||
printf("v: %d\n", FIX2INT(v));
|
||||
eval("yoda");
|
||||
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