Created
February 2, 2013 21:10
-
-
Save shtirlic/4699250 to your computer and use it in GitHub Desktop.
run mruby code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
/* Include the mruby headers */ | |
#include <mruby.h> | |
#include <mruby/proc.h> | |
#include <mruby/data.h> | |
#include <mruby/compile.h> | |
int main(int argc, const char * argv[]) | |
{ | |
struct mrb_parser_state *p; | |
mrb_state *mrb = mrb_open(); | |
mrbc_context *c = mrbc_context_new(mrb); | |
char code[] = "p 'hello world!'"; | |
printf("Executing code with mruby!\n"); | |
p = mrb_parse_string(mrb, code, c); | |
int n; | |
n = mrb_generate_code(mrb, p); | |
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)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment