Created
November 9, 2012 01:36
-
-
Save cadwallion/4043168 to your computer and use it in GitHub Desktop.
Mruby hello world interpreting
This file contains hidden or 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 <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