/* Initializes the functionality that Eruta exposes to Ruby. */ int tr_init(mrb_state * mrb) { // luaL_dostring(lua, "print 'Hello!' "); struct RClass *krn; struct RClass *pth; struct RClass *sto; struct RClass *gra; struct RClass *spr; struct RClass *thi; struct RClass *eru; struct RClass *aud; eru = mrb_define_module(mrb, "Eruta"); pth = mrb_define_class_under(mrb, eru, "Path" , mrb->object_class); MRB_SET_INSTANCE_TT(pth, MRB_TT_DATA); /* Define some constants. */ TR_CONST_INT(mrb, eru, "FLIP_HORIZONTAL", ALLEGRO_FLIP_HORIZONTAL); TR_CONST_INT(mrb, eru, "FLIP_VERTICAL" , ALLEGRO_FLIP_VERTICAL); TR_CONST_INT(mrb, eru, "ALIGN_LEFT" , ALLEGRO_ALIGN_LEFT); TR_CONST_INT(mrb, eru, "ALIGN_CENTRE" , ALLEGRO_ALIGN_CENTRE); TR_CONST_INT(mrb, eru, "ALIGN_CENTER" , ALLEGRO_ALIGN_CENTER); TR_CONST_INT(mrb, eru, "ALIGN_RIGHT" , ALLEGRO_ALIGN_RIGHT); TR_CONST_INT(mrb, eru, "ALIGN_INTEGER" , ALLEGRO_ALIGN_INTEGER); TR_CLASS_METHOD_NOARG(mrb, eru, "quit" , tr_state_done); krn = mrb_module_get(mrb, "Kernel"); if(!krn) return -1; TR_METHOD_ARGC(mrb, krn, "test" , tr_test , 1); TR_METHOD_ARGC(mrb, krn, "warn" , tr_warn , 1); TR_METHOD_ARGC(mrb, krn, "warning" , tr_warn , 1); TR_METHOD_ARGC(mrb, krn, "log" , tr_log , 1); TR_METHOD_ARGC(mrb, krn, "log_to" , tr_log_to , 2); TR_METHOD_ARGC(mrb, krn, "log_enable" , tr_log_disable , 1); TR_METHOD_ARGC(mrb, krn, "log_disable" , tr_log_enable , 1); TR_METHOD_ARGC(mrb, krn, "script" , tr_script , 1); TR_METHOD_ARGC(mrb, krn, "camera_track" , tr_camera_track, 1); TR_METHOD_ARGC(mrb, krn, "camera_lockin", tr_lockin_maplayer, 1); TR_METHOD_NOARG(mrb, krn, "camera_x" , tr_camera_x); TR_METHOD_NOARG(mrb, krn, "camera_y" , tr_camera_y); TR_METHOD_NOARG(mrb, krn, "camera_w" , tr_camera_w); TR_METHOD_NOARG(mrb, krn, "camera_h" , tr_camera_h); /* */ TR_METHOD_NOARG(mrb, krn, "active_map", tr_active_map); TR_METHOD_ARGC(mrb, krn, "active_map_", tr_active_map_, 1); TR_CLASS_METHOD_NOARG(mrb, eru, "active_map", tr_active_map); TR_CLASS_METHOD_ARGC(mrb, eru, "active_map_", tr_active_map_, 1); TR_CLASS_METHOD_NOARG(mrb, eru, "show_fps", tr_show_fps); TR_CLASS_METHOD_NOARG(mrb, eru, "show_area", tr_show_area); TR_CLASS_METHOD_NOARG(mrb, eru, "show_graph", tr_show_graph); TR_CLASS_METHOD_NOARG(mrb, eru, "show_physics", tr_show_physics); TR_CLASS_METHOD_ARGC(mrb, eru, "show_fps=" , tr_show_fps_, 1); TR_CLASS_METHOD_ARGC(mrb, eru, "show_area=" , tr_show_area_, 1); TR_CLASS_METHOD_ARGC(mrb, eru, "show_graph=", tr_show_graph_, 1); TR_CLASS_METHOD_NOARG(mrb, eru, "show_physics=", tr_show_physics_); TR_CLASS_METHOD_ARGC(mrb, eru, "show_mouse_cursor=", tr_show_mouse_cursor_, 1); TR_CLASS_METHOD_NOARG(mrb, eru, "time", tr_get_time); /* Set up submodules. */ tr_sprite_init(mrb, eru); tr_thing_init(mrb, eru); tr_store_init(mrb, eru); tr_graph_init(mrb, eru); tr_audio_init(mrb, eru); // must restore gc area here ???? mrb_gc_arena_restore(mrb, 0); return 0; }
/* Initializes the functionality that Eruta exposes to Ruby. */ int tr_init(mrb_state * mrb) { // luaL_dostring(lua, "print 'Hello!' "); struct RClass *krn; struct RClass *pth; struct RClass *sto; struct RClass *gra; struct RClass *spr; struct RClass *thi; struct RClass *eru; struct RClass *aud; struct RClass *cam; struct RClass *sky; mrb->ud = state_get(); eru = mrb_define_module(mrb, "Eruta"); pth = mrb_define_class_under(mrb, eru, "Path" , mrb->object_class); MRB_SET_INSTANCE_TT(pth, MRB_TT_DATA); /* Define some constants. */ TR_CONST_INT(mrb, eru, "FLIP_HORIZONTAL", ALLEGRO_FLIP_HORIZONTAL); TR_CONST_INT(mrb, eru, "FLIP_VERTICAL" , ALLEGRO_FLIP_VERTICAL); TR_CONST_INT(mrb, eru, "ALIGN_LEFT" , ALLEGRO_ALIGN_LEFT); TR_CONST_INT(mrb, eru, "ALIGN_CENTRE" , ALLEGRO_ALIGN_CENTRE); TR_CONST_INT(mrb, eru, "ALIGN_CENTER" , ALLEGRO_ALIGN_CENTER); TR_CONST_INT(mrb, eru, "ALIGN_RIGHT" , ALLEGRO_ALIGN_RIGHT); TR_CONST_INT(mrb, eru, "ALIGN_INTEGER" , ALLEGRO_ALIGN_INTEGER); TR_CLASS_METHOD_NOARG(mrb, eru, "quit" , tr_state_done); krn = mrb_module_get(mrb, "Kernel"); if(!krn) return -1; TR_METHOD_ARGC(mrb, krn, "test" , tr_test , 1); TR_METHOD_ARGC(mrb, krn, "warn" , tr_warn , 1); TR_METHOD_ARGC(mrb, krn, "warning" , tr_warn , 1); TR_METHOD_ARGC(mrb, krn, "log" , tr_log , 1); TR_METHOD_ARGC(mrb, krn, "log_to" , tr_log_to , 2); TR_METHOD_ARGC(mrb, krn, "log_enable" , tr_log_disable , 1); TR_METHOD_ARGC(mrb, krn, "log_disable" , tr_log_enable , 1); TR_METHOD_ARGC(mrb, krn, "script" , tr_script , 1); cam = mrb_define_module_under(mrb, eru, "Camera"); TR_METHOD_ARGC(mrb, krn, "camera_track" , tr_camera_track, 1); TR_METHOD_ARGC(mrb, krn, "camera_lockin", tr_lockin_maplayer, 1); TR_METHOD_NOARG(mrb, krn, "camera_x" , tr_camera_x); TR_METHOD_NOARG(mrb, krn, "camera_y" , tr_camera_y); TR_METHOD_NOARG(mrb, krn, "camera_w" , tr_camera_w); TR_METHOD_NOARG(mrb, krn, "camera_h" , tr_camera_h); TR_METHOD_NOARG(mrb, krn, "camera_alpha", tr_camera_alpha); TR_METHOD_NOARG(mrb, krn, "camera_theta", tr_camera_theta); TR_METHOD_NOARG(mrb, krn, "camera_fov" , tr_camera_fov); TR_CLASS_METHOD_NOARG(mrb, cam, "x" , tr_camera_x); TR_CLASS_METHOD_NOARG(mrb, cam, "y" , tr_camera_y); TR_CLASS_METHOD_NOARG(mrb, cam, "z" , tr_camera_z); TR_CLASS_METHOD_NOARG(mrb, cam, "w" , tr_camera_w); TR_CLASS_METHOD_NOARG(mrb, cam, "h" , tr_camera_h); TR_CLASS_METHOD_NOARG(mrb, cam, "alpha", tr_camera_alpha); TR_CLASS_METHOD_NOARG(mrb, cam, "theta", tr_camera_theta); TR_CLASS_METHOD_NOARG(mrb, cam, "fov" , tr_camera_fov); TR_CLASS_METHOD_ARGC(mrb, cam, "x=" , tr_camera_x_, 1); TR_CLASS_METHOD_ARGC(mrb, cam, "y=" , tr_camera_y_, 1); TR_CLASS_METHOD_ARGC(mrb, cam, "z=" , tr_camera_z_, 1); TR_CLASS_METHOD_ARGC(mrb, cam, "alpha=", tr_camera_alpha_, 1); TR_CLASS_METHOD_ARGC(mrb, cam, "theta=", tr_camera_theta_, 1); TR_CLASS_METHOD_ARGC(mrb, cam, "fov=" , tr_camera_fov_, 1); sky = mrb_define_module_under(mrb, eru, "Sky"); TR_CLASS_METHOD_ARGC(mrb, sky, "set_texture", tr_skybox_set_texture, 2); TR_CLASS_METHOD_ARGC(mrb, sky, "set_rgb" , tr_skybox_set_rgb, 5); TR_CONST_INT_EASY(mrb, sky, SKYBOX_, DIRECTION_UP); TR_CONST_INT_EASY(mrb, sky, SKYBOX_, DIRECTION_DOWN); TR_CONST_INT_EASY(mrb, sky, SKYBOX_, DIRECTION_NORTH); TR_CONST_INT_EASY(mrb, sky, SKYBOX_, DIRECTION_EAST); TR_CONST_INT_EASY(mrb, sky, SKYBOX_, DIRECTION_SOUTH); TR_CONST_INT_EASY(mrb, sky, SKYBOX_, DIRECTION_WEST); TR_CONST_INT(mrb, eru, "FLIP_HORIZONTAL", ALLEGRO_FLIP_HORIZONTAL); /* */ TR_CLASS_METHOD_NOARG(mrb, eru, "show_fps", tr_show_fps); TR_CLASS_METHOD_NOARG(mrb, eru, "show_area", tr_show_area); TR_CLASS_METHOD_NOARG(mrb, eru, "show_graph", tr_show_graph); TR_CLASS_METHOD_ARGC(mrb, eru, "show_fps=" , tr_show_fps_, 1); TR_CLASS_METHOD_ARGC(mrb, eru, "show_area=" , tr_show_area_, 1); TR_CLASS_METHOD_ARGC(mrb, eru, "show_graph=", tr_show_graph_, 1); TR_CLASS_METHOD_ARGC(mrb, eru, "show_mouse_cursor=", tr_show_mouse_cursor_, 1); TR_CLASS_METHOD_NOARG(mrb, eru, "time", tr_get_time); /* Set up submodules. */ tr_sprite_init(mrb, eru); tr_store_init(mrb, eru); tr_graph_init(mrb, eru); tr_audio_init(mrb, eru); // must restore gc area here ???? mrb_gc_arena_restore(mrb, 0); return 0; }