Last active
February 2, 2016 13:17
-
-
Save keizo042/ec8ae7874ed5ac71d882 to your computer and use it in GitHub Desktop.
mrubyでblockを取り回したい、そのいち
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 <stdio.h> | |
#include <stdlib.h> | |
#include "mruby.h" | |
#include "mruby/compile.h" | |
mrb_value mrb_f(mrb_state *mrb,mrb_value self) | |
{ | |
mrb_value v; | |
mrb_get_args(mrb, "&",v); | |
return self; | |
} | |
int | |
main(int argc, char* argv[]) { | |
FILE *fp; | |
mrb_state *mrb; | |
fp =fopen("sample.rb", "r"); | |
if(fp == NULL) | |
{ | |
return -1; | |
} | |
mrb = mrb_open(); | |
struct RClass *sample = mrb_define_class(mrb, "Sample", mrb->object_class); | |
mrb_define_class_method(mrb, sample, "f", mrb_f, MRB_ARGS_REQ(1)); | |
mrb_value v = mrb_load_file(mrb, fp); | |
mrb_p(mrb, v); | |
mrb_close(mrb); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment