Skip to content

Instantly share code, notes, and snippets.

@keizo042
Last active February 2, 2016 13:17
Show Gist options
  • Save keizo042/ec8ae7874ed5ac71d882 to your computer and use it in GitHub Desktop.
Save keizo042/ec8ae7874ed5ac71d882 to your computer and use it in GitHub Desktop.
mrubyでblockを取り回したい、そのいち
#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