Skip to content

Instantly share code, notes, and snippets.

@shtirlic
Created February 2, 2013 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shtirlic/4699250 to your computer and use it in GitHub Desktop.
Save shtirlic/4699250 to your computer and use it in GitHub Desktop.
run mruby code
#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