Created
April 30, 2014 21:40
-
-
Save scalone/11439246 to your computer and use it in GitHub Desktop.
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 <ctype.h> | |
#include <string.h> | |
/* Include the mruby headers */ | |
#include <mruby.h> | |
#include <mruby/proc.h> | |
#include <mruby/data.h> | |
#include <mruby/compile.h> | |
#include "mruby/dump.h" | |
#include "mruby/string.h" | |
#include "mruby/irep.h" | |
#include "mruby/numeric.h" | |
#include "mruby/debug.h" | |
#include "mruby/proc.h" | |
int main(int argc, const char * argv[]) | |
{ | |
struct mrb_parser_state *p; | |
size_t bin_size = 0; | |
uint8_t *bin = NULL; | |
mrbc_context *c; | |
mrb_value result; | |
mrb_state *mrb = mrb_open(); | |
char code[] = "p 'hello world!'"; | |
printf("Executing code with mruby!\n"); | |
c = mrbc_context_new(mrb); | |
c->no_exec = 1; | |
mrbc_filename(mrb, c, code); | |
result = mrb_load_string_cxt(mrb, code, c); | |
mrbc_context_free(mrb, c); | |
dump_irep(mrb, mrb_proc_ptr(result)->body.irep, 1, &bin, &bin_size); | |
printf("%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X", bin[0], bin[1], bin[2], bin[3], bin[4], bin[5], bin[6], bin[7], bin[8]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment