changes to mrb_load_string() version

magewhopper
2012-07-05 06:15:29 -07:00
parent 65fbc1e213
commit a9c4ecb718
+2 -11
@@ -4,24 +4,15 @@
/* Include the mruby header */
#include <mruby.h>
#include <mruby/proc.h>
#include <mruby/data.h>
#include <mruby/compile.h>
int main(void)
{
struct mrb_parser_state *p;
mrb_state *mrb = mrb_open();
char code[] = "p 'hello world!'";
printf("Executing Ruby code from C!\n");
p = mrb_parse_string(mrb, code, NULL);
int n;
n = mrb_generate_code(mrb, p->tree);
mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
if (mrb->exc) {
mrb_p(mrb, mrb_obj_value(mrb->exc));
}
mrb_load_string(mrb, code);
return 0;
}
```
@@ -29,7 +20,7 @@ compile & link
```
$ gcc -Iinclude hello.c lib/libmruby.a -lm -o hello.out
```
execute
execution
```
$ ./hello.out
Executing Ruby code from C!