Last active
January 24, 2017 14:36
-
-
Save i110/e06bd83e6debf9a7d070bb76f25f5fda to your computer and use it in GitHub Desktop.
generated RProc as an argument?
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 <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