Skip to content

Instantly share code, notes, and snippets.

@i110
Last active January 24, 2017 14:36
Show Gist options
  • Save i110/e06bd83e6debf9a7d070bb76f25f5fda to your computer and use it in GitHub Desktop.
Save i110/e06bd83e6debf9a7d070bb76f25f5fda to your computer and use it in GitHub Desktop.
generated RProc as an argument?
#include <stdlib.h>
#include <stdio.h>
#include <mruby.h>
#include <mruby/compile.h>
int main(void)
{
mrb_state *mrb = mrb_open();
mrbc_context *ctx = mrbc_context_new(mrb);
const char *code = "puts 'hello world!'\n";
struct mrb_parser_state *parser = mrb_parse_string(mrb, code, ctx);
struct RProc *argproc = mrb_generate_code(mrb, parser);
mrb_value arg = mrb_obj_value(argproc);
mrb_value receiver = mrb_load_string(mrb, "proc {|arg| arg.call }");
mrb_funcall_argv(mrb, receiver, mrb_intern_lit(mrb, "call"), 1, &arg);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment