Skip to content

Instantly share code, notes, and snippets.

@cadwallion
Created November 9, 2012 01:36
Show Gist options
  • Save cadwallion/4043168 to your computer and use it in GitHub Desktop.
Save cadwallion/4043168 to your computer and use it in GitHub Desktop.
Mruby hello world interpreting
#include <iostream>
#include <mruby.h>
#include <mruby/proc.h>
#include <mruby/compile.h>
void eval_expanded(mrb_state *mrb, char code[]) {
struct mrb_parser_state *p;
mrbc_context *context = mrbc_context_new(mrb);
p = mrb_parse_string(mrb, code, context);
int n = mrb_generate_code(mrb, p);
mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
}
void eval(mrb_state *mrb, char code[]) {
mrb_load_string(mrb, code);
}
int main(int argc, const char * argv[])
{
mrb_state *mrb = mrb_open();
char code[] = "p 'hello from ruby world!'";
eval(mrb, code);
std::cout << "hello from c++ world!" << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment