예제 #1
0
파일: step4.c 프로젝트: townsen/embedruby
int main()
{
  mrb_state *mrb;
  int n;
  FILE* f;
  struct RClass* cObject;
  mrbc_context *mrbc_ctx;
  struct mrb_parser_state *p;

  mrb = mrb_open();
  mrbc_ctx = mrbc_context_new(mrb);
  cObject = mrb_class_obj_get(mrb, "Object");
  mrb_define_method(mrb, cObject, "plus", plus, ARGS_ANY());
  //mrb_define_singleton_method(mrb, mrb_top_self(mrb), "plus", plus, ARGS_REQ(2));
  f = fopen("step4.rb", "r");
  if(f==NULL){ _error("file not found."); }
  p = mrb_parse_file(mrb,f,mrbc_ctx);
  fclose(f);
  n = mrb_generate_code(mrb, p);
  mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_nil_value());
  mrb_parser_free(p);
  mrbc_context_free(mrb,mrbc_ctx);
  mrb_close(mrb);
  return 0;
}
예제 #2
0
파일: step4.c 프로젝트: yielding/code
int main()
{
  mrb_state *mrb;
  int n;
  FILE* f;
  struct RClass* cObject;

  mrb = mrb_open();
  cObject = mrb_class_obj_get(mrb, "Object");
  mrb_define_method(mrb, cObject, "plus", plus, ARGS_ANY());
  //mrb_define_singleton_method(mrb, mrb_top_self(mrb), "plus", plus, ARGS_REQ(2));
  f = fopen("step4.rb", "r");
  if(f==NULL){ _error("file not found."); }
  n = mrb_load_file(mrb, f);
  fclose(f);
  mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_nil_value());
  mrb_close(mrb);
}