示例#1
0
文件: sekigae.c 项目: Joe-noh/sekigae
int main() {

  FILE *fp;
  if ((fp = fopen("./member.conf", "r")) == NULL)
    return 1;

  mrb_state* mrb = mrb_open();
  mrb_load_file(mrb, fp);

  mrb_value member;
  mrb_get_config_value(mrb, "member", "o", &member);
  mrb_value mnum = mrb_funcall(mrb, member, "size", 0);

  int i;
  int seki_num = mrb_fixnum(mnum);
  for (i = 0; i < seki_num; i++) {
    mnum = mrb_funcall(mrb, member, "size", 0);
    mrb_value seki = mrb_funcall(mrb, mrb_top_self(mrb), "rand", 1, mnum);
    mrb_p(mrb, mrb_funcall(mrb, member, "[]", 1, seki));
    mrb_funcall(mrb, member, "delete_at", 1, seki);
  }

  mrb_close(mrb);

  return 0;
}
 mrb_value ScriptEngine::loadPath(std::string path) {
     FILE *fp = fopen(path.c_str(), "r");
     if(! fp) {
         throw FileNotFoundError(path);
     }
     mrb_value v = mrb_load_file(mrb.get(), fp);
     fclose(fp);
     return v;
 }
示例#3
0
int
main(void)
{
  mrb_state* mrb = mrb_open();
  FILE *fp = fopen("mruby.rb", "r");
  mrb_load_file(mrb, fp);
  mrb_close(mrb);

  return 0;
}
示例#4
0
VCL_INT vmod_conf_path(VRT_CTX, struct vmod_priv *priv, VCL_STRING path)
{
    mrb_state *mrb= (mrb_state*)priv->priv;
    FILE *fp;
    //mrb_value v;

    fp = fopen(path,"r");
    if(fp == NULL)
    {
        return -1;
    }
    mrb_load_file(mrb,fp);
    return 0;
}
示例#5
0
int main()
{

  mrb_state* mrb;
  int n;
  FILE* f;
  mrb_value ret;

  mrb = mrb_open();
  f = fopen("test.rb", "r");
  mrb_load_file(mrb, f);
  fclose(f);

  ret = mrb_funcall(mrb, mrb_top_self(mrb), "test", 1, mrb_fixnum_value(20) );
  
  //mrb_define_method(mrb, mrb->kernel_module, "cursor_move", cursor_move, MRB_ARGS_REQ(2));
//------------------------------------------

  int  x, y;
  int key=' ';
  char *str;
  initscr();
  keypad(stdscr, TRUE);

  setlocale(LC_ALL, "");

  x = 0;
  y = 0;

  while (1) {
    key = getch();
    ret = mrb_funcall(mrb, mrb_top_self(mrb), "evaluate", 1, mrb_fixnum_value(key) );
    str = mrb_string_value_ptr(mrb, ret);
    addstr(str);
    if (key == 'q') break;
    switch (key) {
      case KEY_UP: y--; break;
      case KEY_DOWN: y++; break;
      case KEY_LEFT: x--; break;
      case KEY_RIGHT: x++; break;
      default : mvprintw(y, x++, "%c", key); break;
    }
    move(y, x);
    //mrb_load_string(mrb,"cursor_move(x, y);");
  }
  endwin();
  mrb_close(mrb);
  return (0);
}
示例#6
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);
}
示例#7
0
mrb_value 
mrb_game_reload_file(mrb_state* mrb, mrb_value self)
{
  mrb_value path;
  mrb_get_args(mrb, "S", &path);

  char* file_path = mrb_string_value_ptr(mrb, path);

  FILE* file = fopen(file_path, "r");
  if (file == NULL) {
    printf("Error opening file: %s\n", file_path);
    return self;
  }

  mrb_load_file(mrb,file);

  fclose(file);

  return self;
}
示例#8
0
//----------------------------------------------------------
void ScriptEngine::load()
{
    FILE *fd = fopen(mScriptPath, "r");
    mrb_load_file(mMrb, fd);
    fclose(fd);
}
示例#9
0
文件: glmruby.c 项目: mirichi/glmruby
int main(int argc, char *argv[])
{
  mrb_value s;
  FILE *fp;
  DIR *dp;
  struct dirent *dirst;

  mrb_state *mrb  = mrb_open();

  glmrb_sprite_init(mrb);
  glmrb_input_init(mrb);

  dp = opendir("./lib");
  while((dirst = readdir(dp)) != NULL)
  {
    char buf[256];
    if (dirst->d_name[0] == '.') continue;
    strcpy(buf, "./lib/");
    strcat(buf, dirst->d_name);
    fp = fopen(buf, "r");
    mrb_load_file(mrb, fp);
    fclose(fp);
  }
  closedir(dp);

  fp = fopen("main.rb", "r");
  s = mrb_load_file(mrb, fp);
  fclose(fp);

  /* SDL初期化 */
  if (SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    exit(-1);
  }

  /* フレームバッファ作成 */
  mWIN = SDL_SetVideoMode(640, 480, 0, 0);
  if (!mWIN) {
    SDL_Quit();
    exit(-1);
  }

  /* キャプション設定 */
  SDL_WM_SetCaption("glmruby application",NULL);

  /* メインループ */
  while(quits() != 0) {

    mrb_funcall(mrb, s, "update", 0);

    /* 画面消去 */
    SDL_FillRect(mWIN, NULL, SDL_MapRGB(mWIN->format, 0, 0, 0));

    mrb_funcall(mrb, s, "draw", 0);

    /* ウェイト処理 */
    timer.now = SDL_GetTicks();
    timer.wit = timer.now - timer.lev;
    if (timer.wit < 16) SDL_Delay(16 - timer.wit);
    timer.lev = SDL_GetTicks();

    /* 画面更新 */
    SDL_UpdateRect(mWIN, 0, 0, 0, 0);
  }

  /* 終了処理 */
  SDL_Quit();
  return 0;
}