void mrb_mruby_base58_gem_init(mrb_state *mrb) { base58 = mrb_define_module(mrb, "Base58"); mrb_define_module_function(mrb, base58, "encode", mrb_base58_encode, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(1)); mrb_define_module_function(mrb, base58, "decode", mrb_base58_decode, MRB_ARGS_REQ(1) | MRB_ARGS_OPT(1)); DONE; }
void MessagePack_Packer_module_init(mrb_state* mrb, struct RClass *mMessagePack) { sym_pack_data = mrb_intern_cstr(mrb, "pack_data"); //s_to_msgpack = mrb_intern_cstr(mrb, "to_msgpack"); s_write = mrb_intern_cstr(mrb, "write"); cMessagePack_Packer = mrb_define_class_under(mrb, mMessagePack, "Packer", mrb->object_class); mrb_define_method(mrb, cMessagePack_Packer, "initialize", Packer_initialize, MRB_ARGS_ANY()/* -1 */); mrb_define_method(mrb, cMessagePack_Packer, "buffer", Packer_buffer, MRB_ARGS_NONE()/*0*/); mrb_define_method(mrb, cMessagePack_Packer, "write", Packer_write, MRB_ARGS_REQ(1) /*1*/); mrb_define_alias(mrb, cMessagePack_Packer, "pack", "write"); mrb_define_method(mrb, cMessagePack_Packer, "write_nil", Packer_write_nil, MRB_ARGS_NONE()/*0*/); mrb_define_method(mrb, cMessagePack_Packer, "write_array_header", Packer_write_array_header, MRB_ARGS_REQ(1) /*1*/); mrb_define_method(mrb, cMessagePack_Packer, "write_map_header", Packer_write_map_header, MRB_ARGS_REQ(1) /*1*/); mrb_define_method(mrb, cMessagePack_Packer, "flush", Packer_flush, MRB_ARGS_NONE()/*0*/); /* delegation methods */ mrb_define_method(mrb, cMessagePack_Packer, "clear", Packer_clear, MRB_ARGS_NONE()); mrb_define_method(mrb, cMessagePack_Packer, "size", Packer_size, MRB_ARGS_NONE()); mrb_define_method(mrb, cMessagePack_Packer, "empty?", Packer_empty_p, MRB_ARGS_NONE()); //mrb_define_method(mrb, cMessagePack_Packer, "write_to", Packer_write_to, MRB_ARGS_REQ(1) ); mrb_define_method(mrb, cMessagePack_Packer, "to_str", Packer_to_str, MRB_ARGS_NONE()); mrb_define_alias(mrb, cMessagePack_Packer, "to_s", "to_str"); mrb_define_method(mrb, cMessagePack_Packer, "to_a", Packer_to_a, MRB_ARGS_NONE()); /* MessagePack.pack(x) */ mrb_define_module_function(mrb, mMessagePack, "pack", MessagePack_pack_module_method, MRB_ARGS_ANY()/* -1 */); mrb_define_module_function(mrb, mMessagePack, "dump", MessagePack_dump_module_method, MRB_ARGS_ANY()/* -1 */); }
void mrb_mruby_dir_gem_init(mrb_state* mrb) { mrb_dir_class = mrb_define_module(mrb, "Dir"); mrb_define_module_function(mrb, mrb_dir_class, "entries", mrb_dir_entries, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_dir_class, "exists?", mrb_dir_exists, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_dir_class, "exist?", mrb_dir_exists, MRB_ARGS_REQ(1)); }
void mrb_mruby_pcap_gem_init(mrb_state *mrb) { struct RClass *pcap, *capt; pcap = mrb_define_module(mrb, "Pcap"); mrb_define_module_function(mrb, pcap, "lookupdev", mrb_pcap_s_lookupdev, ARGS_NONE()); mrb_define_module_function(mrb, pcap, "lookupnet", pcap_s_lookupnet, ARGS_REQ(1)); mrb_define_const(mrb, pcap, "DLT_NULL", mrb_fixnum_value(DLT_NULL)); mrb_define_const(mrb, pcap, "DLT_EN10MB", mrb_fixnum_value(DLT_EN10MB)); mrb_define_const(mrb, pcap, "DLT_PPP", mrb_fixnum_value(DLT_PPP)); #ifdef DLT_RAW mrb_define_const(mrb, pcap, "DLT_RAW", mrb_fixnum_value(DLT_RAW)); #endif capt = mrb_define_class_under(mrb, pcap, "Capture", mrb->object_class); mrb_define_singleton_method(mrb, (struct RObject*)capt, "open_live", mrb_capture_open_live, MRB_ARGS_ARG(1, 3)); mrb_define_method(mrb, capt, "capture", capture, ARGS_NONE()); mrb_define_method(mrb, capt, "close", capture_close, ARGS_NONE()); mrb_define_method(mrb, capt, "datalink", capture_datalink, ARGS_NONE()); mrb_define_method(mrb, capt, "inject", mrb_capture_inject, MRB_ARGS_REQ(1)); mrb_define_method(mrb, capt, "setfilter", capture_setfilter, ARGS_ANY()); }
void mrb_mruby_setuid_gem_init(mrb_state *mrb) { struct RClass *kernel = mrb_module_get(mrb, "Kernel"); mrb_define_module_function(mrb, kernel, "setuid", mrb_setuid, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, kernel, "getuid", mrb_getuid, MRB_ARGS_NONE()); mrb_define_module_function(mrb, kernel, "seteuid", mrb_seteuid, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, kernel, "geteuid", mrb_geteuid, MRB_ARGS_NONE()); }
void mrb_mruby_lz4_gem_init(mrb_state* mrb) { struct RClass *LZ4_mod; LZ4_mod = mrb_define_module(mrb, "LZ4"); mrb_define_class_under(mrb, LZ4_mod, "Error", E_RUNTIME_ERROR); mrb_define_module_function(mrb, LZ4_mod, "compress_default", mrb_LZ4_compress_default, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, LZ4_mod, "decompress_safe", mrb_LZ4_decompress_safe, MRB_ARGS_REQ(2)); }
void mrb_mruby_proc_ext_gem_test(mrb_state *mrb) { struct RClass *cls; cls = mrb_define_class(mrb, "ProcExtTest", mrb->object_class); mrb_define_module_function(mrb, cls, "mrb_proc_new_cfunc_with_env", proc_new_cfunc_with_env, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, cls, "mrb_cfunc_env_get", cfunc_env_get, MRB_ARGS_REQ(2)); mrb_define_module_function(mrb, cls, "cfunc_without_env", cfunc_without_env, MRB_ARGS_NONE()); }
void mruby_sdl2_clipboard_init(mrb_state *mrb) { struct RClass *mod_Clipboard = mrb_define_module_under(mrb, mod_SDL2, "Clipboard"); mrb_define_module_function(mrb, mod_Clipboard, "text", mrb_sdl2_clipboard_text, MRB_ARGS_NONE()); // SDL_GetClipboardText mrb_define_module_function(mrb, mod_Clipboard, "text=", mrb_sdl2_clipboard_set_text, MRB_ARGS_REQ(1)); // SDL_SetClipboardText mrb_define_module_function(mrb, mod_Clipboard, "has_text?", mrb_sdl2_clipboard_has_text, MRB_ARGS_NONE()); // SDL_HasClipboardText }
void mrb_mruby_kernel_ext_gem_init(mrb_state *mrb) { struct RClass *krn = mrb->kernel_module; mrb_define_module_function(mrb, krn, "fail", mrb_f_raise, MRB_ARGS_OPT(2)); mrb_define_method(mrb, krn, "__method__", mrb_f_method, MRB_ARGS_NONE()); mrb_define_module_function(mrb, krn, "String", mrb_f_string, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, krn, "Array", mrb_f_array, MRB_ARGS_REQ(1)); }
void mrb_mruby_error_gem_test(mrb_state *mrb) { struct RClass *cls; cls = mrb_define_class(mrb, "ExceptionTest", mrb->object_class); mrb_define_module_function(mrb, cls, "mrb_protect", run_protect, MRB_ARGS_NONE() | MRB_ARGS_BLOCK()); mrb_define_module_function(mrb, cls, "mrb_ensure", run_ensure, MRB_ARGS_REQ(2)); mrb_define_module_function(mrb, cls, "mrb_rescue", run_rescue, MRB_ARGS_REQ(2)); mrb_define_module_function(mrb, cls, "mrb_rescue_exceptions", run_rescue_exceptions, MRB_ARGS_REQ(2)); }
void mruby_allegro_time_init(mrb_state *mrb) { struct RClass *am = M_ALLEGRO; struct RClass *tc = mrb_define_class_under(mrb, am, "Timeout", mrb->object_class); MRB_SET_INSTANCE_TT(tc, MRB_TT_DATA); mrb_define_module_function(mrb, am, "time", get_time, MRB_ARGS_NONE()); mrb_define_module_function(mrb, am, "current_time", get_time, MRB_ARGS_NONE()); mrb_define_method(mrb, tc, "initialize", timeout_initialize, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, am, "rest", rest, MRB_ARGS_REQ(1)); }
void mruby_sdl2_joystick_init(mrb_state *mrb) { int arena_size; struct RClass *mod_Joystick = mrb_define_module_under(mrb, mod_SDL2, "Joysticks"); class_Joystick = mrb_define_class_under(mrb, mod_Joystick, "Joystick", mrb->object_class); MRB_SET_INSTANCE_TT(class_Joystick, MRB_TT_DATA); mrb_define_module_function(mrb, mod_Joystick, "num", mrb_sdl2_joystick_num, MRB_ARGS_NONE()); mrb_define_module_function(mrb, mod_Joystick, "name_from_index", mrb_sdl2_joystick_get_name, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, mod_Joystick, "get_guid_from_index", mrb_sdl2_joystick_get_guid, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, mod_Joystick, "get_guid_as_string", mrb_sdl2_joystick_get_guid_as_string, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, mod_Joystick, "get_guid_from_string", mrb_sdl2_joystick_get_guid_from_string, MRB_ARGS_REQ(1)); mrb_define_method(mrb, class_Joystick, "initialize", mrb_sdl2_joystick_joystick_initialize, MRB_ARGS_REQ(1)); mrb_define_method(mrb, class_Joystick, "destroy", mrb_sdl2_joystick_joystick_free, MRB_ARGS_NONE()); mrb_define_method(mrb, class_Joystick, "free", mrb_sdl2_joystick_joystick_free, MRB_ARGS_NONE()); mrb_define_method(mrb, class_Joystick, "get_name", mrb_sdl2_joystick_joystick_get_name, MRB_ARGS_NONE()); mrb_define_method(mrb, class_Joystick, "get_guid", mrb_sdl2_joystick_joystick_get_guid, MRB_ARGS_NONE()); mrb_define_method(mrb, class_Joystick, "get_guid_as_string", mrb_sdl2_joystick_joystick_get_guid_as_string, MRB_ARGS_NONE()); mrb_define_method(mrb, class_Joystick, "is_attached?", mrb_sdl2_joystick_joystick_is_attached, MRB_ARGS_NONE()); mrb_define_method(mrb, class_Joystick, "get_id", mrb_sdl2_joystick_joystick_get_id, MRB_ARGS_NONE()); mrb_define_method(mrb, class_Joystick, "get_general_num_axes", mrb_sdl2_joystick_joystick_get_num_axes, MRB_ARGS_NONE()); mrb_define_method(mrb, class_Joystick, "get_general_num_balls", mrb_sdl2_joystick_joystick_get_num_balls, MRB_ARGS_NONE()); mrb_define_method(mrb, class_Joystick, "get_general_num_hats", mrb_sdl2_joystick_joystick_get_num_hats, MRB_ARGS_NONE()); mrb_define_method(mrb, class_Joystick, "get_general_num_buttons", mrb_sdl2_joystick_joystick_get_num_buttons, MRB_ARGS_NONE()); mrb_define_method(mrb, class_Joystick, "update", mrb_sdl2_joystick_joystick_update, MRB_ARGS_NONE()); mrb_define_method(mrb, class_Joystick, "event_state", mrb_sdl2_joystick_joystick_event_state, MRB_ARGS_REQ(1)); mrb_define_method(mrb, class_Joystick, "get_axis", mrb_sdl2_joystick_joystick_get_axis, MRB_ARGS_REQ(1)); mrb_define_method(mrb, class_Joystick, "get_axis_x", mrb_sdl2_joystick_joystick_get_axis_x, MRB_ARGS_NONE()); mrb_define_method(mrb, class_Joystick, "get_axis_y", mrb_sdl2_joystick_joystick_get_axis_y, MRB_ARGS_NONE()); mrb_define_method(mrb, class_Joystick, "get_hat", mrb_sdl2_joystick_joystick_get_hat, MRB_ARGS_REQ(1)); mrb_define_method(mrb, class_Joystick, "get_ball", mrb_sdl2_joystick_joystick_get_ball, MRB_ARGS_REQ(1)); mrb_define_method(mrb, class_Joystick, "get_button", mrb_sdl2_joystick_joystick_get_button, MRB_ARGS_REQ(1)); arena_size = mrb_gc_arena_save(mrb); mrb_define_const(mrb, mod_Joystick, "SDL_HAT_CENTERED", mrb_fixnum_value(SDL_HAT_CENTERED)); mrb_define_const(mrb, mod_Joystick, "SDL_HAT_UP", mrb_fixnum_value(SDL_HAT_UP)); mrb_define_const(mrb, mod_Joystick, "SDL_HAT_RIGHT", mrb_fixnum_value(SDL_HAT_RIGHT)); mrb_define_const(mrb, mod_Joystick, "SDL_HAT_DOWN", mrb_fixnum_value(SDL_HAT_DOWN)); mrb_define_const(mrb, mod_Joystick, "SDL_HAT_LEFT", mrb_fixnum_value(SDL_HAT_LEFT)); mrb_define_const(mrb, mod_Joystick, "SDL_HAT_RIGHTUP", mrb_fixnum_value(SDL_HAT_RIGHTUP)); mrb_define_const(mrb, mod_Joystick, "SDL_HAT_RIGHTDOWN", mrb_fixnum_value(SDL_HAT_RIGHTDOWN)); mrb_define_const(mrb, mod_Joystick, "SDL_HAT_LEFTUP", mrb_fixnum_value(SDL_HAT_LEFTUP)); mrb_define_const(mrb, mod_Joystick, "SDL_HAT_LEFTDOWN", mrb_fixnum_value(SDL_HAT_LEFTDOWN)); mrb_gc_arena_restore(mrb, arena_size); }
void mrb_init_uefi_boot_service(mrb_state *mrb, struct RClass *mrb_uefi) { struct RClass *bs; bs = mrb_define_module_under(mrb, mrb_uefi, "BootService"); mrb_define_module_function(mrb, bs, "pointer", bs_pointer, ARGS_NONE()); mrb_define_module_function(mrb, bs, "handle_protocol", bs_handle_protocol, ARGS_REQ(2)); mrb_define_module_function(mrb, bs, "protocols_per_handle", bs_protocols_per_handle, ARGS_REQ(1)); mrb_define_module_function(mrb, bs, "locate_handle_buffer", bs_locate_handle_buffer, ARGS_REQ(1)); mrb_define_module_function(mrb, bs, "locate_protocol", bs_locate_protocol, ARGS_REQ(1)); }
void mrb_mruby_kernel_ext_gem_init(mrb_state *mrb) { struct RClass *krn = mrb->kernel_module; mrb_define_module_function(mrb, krn, "fail", mrb_f_raise, MRB_ARGS_NONE()); }
void mrb_mruby_mrmagick_gem_init(mrb_state *mrb) { struct RClass *mrmagick_module; struct RClass *mrmagick; myInitializeMagick(); mrmagick_module = mrb_define_module(mrb, "Mrmagick"); mrb_define_module_function(mrb, mrmagick_module, "capi_formats", mrb_mrmagick_formats, MRB_ARGS_NONE()); mrmagick = mrb_define_class_under(mrb, mrmagick_module, "Capi", mrb->object_class); /*mrb_define_method(mrb, mrmagick, "initialize", mrb_mrmagick_init, MRB_ARGS_REQ(1));*/ mrb_define_class_method(mrb, mrmagick, "scale", mrb_mrmagick_scale, MRB_ARGS_REQ(3)); mrb_define_class_method(mrb, mrmagick, "blur", mrb_mrmagick_blur, MRB_ARGS_REQ(4)); mrb_define_class_method(mrb, mrmagick, "rm", mrb_mrmagick_rm, MRB_ARGS_REQ(1)); mrb_define_class_method(mrb, mrmagick, "write", mrb_mrmagick_write, MRB_ARGS_REQ(1)); mrb_define_class_method(mrb, mrmagick, "write_gif", mrb_mrmagick_write_gif, MRB_ARGS_REQ(1)); mrb_define_class_method(mrb, mrmagick, "to_blob", mrb_mrmagick_to_blob, MRB_ARGS_REQ(1)); mrb_define_class_method(mrb, mrmagick, "get_exif_by_entry", mrb_mrmagick_get_exif_by_entry, MRB_ARGS_REQ(1)); mrb_define_class_method(mrb, mrmagick, "get_columns", mrb_mrmagick_get_columns, MRB_ARGS_REQ(1)); mrb_define_class_method(mrb, mrmagick, "get_rows", mrb_mrmagick_get_rows, MRB_ARGS_REQ(1)); mrb_define_class_method(mrb, mrmagick, "get_format", mrb_mrmagick_get_format, MRB_ARGS_REQ(1)); DONE; }
//************************************************** // ライブラリを定義します //************************************************** void kernel_Init(mrb_state *mrb) { mrb_define_method(mrb, mrb->kernel_module, "pinMode", mrb_kernel_pinMode, MRB_ARGS_REQ(2)); mrb_define_method(mrb, mrb->kernel_module, "digitalWrite", mrb_kernel_digitalWrite, MRB_ARGS_REQ(2)); mrb_define_method(mrb, mrb->kernel_module, "pwm", mrb_kernel_pwm, MRB_ARGS_REQ(2)); mrb_define_method(mrb, mrb->kernel_module, "digitalRead", mrb_kernel_digitalRead, MRB_ARGS_REQ(1)); mrb_define_method(mrb, mrb->kernel_module, "analogReference", mrb_kernel_analogReference, MRB_ARGS_REQ(1)); mrb_define_method(mrb, mrb->kernel_module, "analogRead", mrb_kernel_analogRead, MRB_ARGS_REQ(1)); mrb_define_method(mrb, mrb->kernel_module, "tone", mrb_kernel_tone, MRB_ARGS_REQ(2)|MRB_ARGS_OPT(1)); mrb_define_method(mrb, mrb->kernel_module, "noTone", mrb_kernel_noTone, MRB_ARGS_REQ(1)); //mrb_define_method(mrb, mrb->kernel_module, "pwmHz", mrb_kernel_pwmHz, MRB_ARGS_REQ(1)); mrb_define_method(mrb, mrb->kernel_module, "initDac", mrb_kernel_initDac, MRB_ARGS_NONE()); mrb_define_method(mrb, mrb->kernel_module, "analogDac", mrb_kernel_analogDac, MRB_ARGS_REQ(1)); mrb_define_method(mrb, mrb->kernel_module, "delay", mrb_kernel_delay, MRB_ARGS_REQ(1)); mrb_define_method(mrb, mrb->kernel_module, "millis", mrb_kernel_millis, MRB_ARGS_NONE()); mrb_define_method(mrb, mrb->kernel_module, "micros", mrb_kernel_micros, MRB_ARGS_NONE()); mrb_define_method(mrb, mrb->kernel_module, "led", mrb_kernel_led, MRB_ARGS_REQ(1)); mrb_define_method(mrb, mrb->kernel_module, "randomSeed", mrb_kernel_randomSeed, MRB_ARGS_REQ(1)); mrb_define_method(mrb, mrb->kernel_module, "random", mrb_kernel_random, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1)); struct RClass *El_PsyModule = mrb_define_module(mrb, "El_Psy"); mrb_define_module_function(mrb, El_PsyModule, "Congroo", mrb_El_Psy_congroo, MRB_ARGS_NONE()); }
//************************************************** // ライブラリを定義します //************************************************** void sys_Init(mrb_state *mrb) { struct RClass *systemModule = mrb_define_module(mrb, "System"); mrb_define_module_function(mrb, systemModule, "exit", mrb_system_exit, MRB_ARGS_NONE()); mrb_define_module_function(mrb, systemModule, "reset", mrb_system_reset, MRB_ARGS_NONE()); mrb_define_module_function(mrb, systemModule, "setrun", mrb_system_setrun, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, systemModule, "version", mrb_system_version, MRB_ARGS_OPT(1)); mrb_define_module_function(mrb, systemModule, "push", mrb_system_push, MRB_ARGS_REQ(3)); mrb_define_module_function(mrb, systemModule, "pop", mrb_system_pop, MRB_ARGS_REQ(2)); mrb_define_module_function(mrb, systemModule, "fileload", mrb_system_fileload, MRB_ARGS_NONE()); mrb_define_module_function(mrb, systemModule, "useSD", mrb_system_useSD, MRB_ARGS_NONE()); mrb_define_module_function(mrb, systemModule, "useWiFi", mrb_system_useWiFi, MRB_ARGS_NONE()); mrb_define_module_function(mrb, systemModule, "getMrbPath", mrb_system_getmrbpath, MRB_ARGS_NONE()); }
void mrb_mruby_rtos_toppers_gem_init(mrb_state *mrb) { struct RClass *rtos; struct RClass *tsk; mrb_value wmd; mrb_value tmo; /* RTOS module */ rtos = mrb_define_module(mrb, "RTOS"); /* RTOS api */ mrb_define_module_function(mrb, rtos, "delay", mrb_rtos_delay, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, rtos, "millis", mrb_rtos_millis, MRB_ARGS_NONE()); wmd = mrb_hash_new(mrb); mrb_hash_set(mrb, wmd, mrb_symbol_value(mrb_intern_lit(mrb, "and")), mrb_fixnum_value(TWF_ANDW)); mrb_hash_set(mrb, wmd, mrb_symbol_value(mrb_intern_lit(mrb, "or")), mrb_fixnum_value(TWF_ORW)); mrb_mod_cv_set(mrb, rtos, mrb_intern_lit(mrb, "WAITMODE"), wmd); tmo = mrb_hash_new(mrb); mrb_hash_set(mrb, tmo, mrb_symbol_value(mrb_intern_lit(mrb, "polling")), mrb_fixnum_value(TMO_POL)); mrb_hash_set(mrb, tmo, mrb_symbol_value(mrb_intern_lit(mrb, "forever")), mrb_fixnum_value(TMO_FEVR)); mrb_mod_cv_set(mrb, rtos, mrb_intern_lit(mrb, "TIMEOUT"), tmo); /* Task class */ tsk = mrb_define_class_under(mrb, rtos, "Task", mrb->object_class); mrb_define_method(mrb, tsk, "initialize", mrb_task_init, MRB_ARGS_REQ(1)); mrb_define_method(mrb, tsk, "activate", mrb_task_activate, MRB_ARGS_NONE()); mrb_define_method(mrb, tsk, "suspend", mrb_task_suspend, MRB_ARGS_NONE()); mrb_define_method(mrb, tsk, "resume", mrb_task_resume, MRB_ARGS_NONE()); mrb_define_method(mrb, tsk, "terminate", mrb_task_terminate, MRB_ARGS_NONE()); /* EventFlag class */ mrb_rtos_flag_init(mrb, rtos); /* MemoryPool, MemoryBuffer */ mrb_rtos_memory_init(mrb, rtos); /* DataQueue */ mrb_rtos_dataqueue_init(mrb, rtos); }
void mrb_mruby_proc_ext_gem_init(mrb_state* mrb) { struct RClass *p = mrb->proc_class; mrb_define_method(mrb, p, "lambda?", mrb_proc_lambda, MRB_ARGS_NONE()); mrb_define_method(mrb, p, "source_location", mrb_proc_source_location, MRB_ARGS_NONE()); mrb_define_method(mrb, p, "to_s", mrb_proc_inspect, MRB_ARGS_NONE()); mrb_define_method(mrb, p, "inspect", mrb_proc_inspect, MRB_ARGS_NONE()); mrb_define_class_method(mrb, mrb->kernel_module, "proc", mrb_kernel_proc, MRB_ARGS_NONE()); mrb_define_method(mrb, mrb->kernel_module, "proc", mrb_kernel_proc, MRB_ARGS_NONE()); mrb_define_module_function(mrb, mrb->kernel_module, "local_variables", mrb_local_variables, MRB_ARGS_NONE()); }
void inputBindingInit(mrb_state *mrb) { RClass *module = mrb_define_module(mrb, "Input"); mrb_define_module_function(mrb, module, "update", inputUpdate, MRB_ARGS_NONE()); mrb_define_module_function(mrb, module, "press?", inputPress, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, module, "trigger?", inputTrigger, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, module, "repeat?", inputRepeat, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, module, "dir4", inputDir4, MRB_ARGS_NONE()); mrb_define_module_function(mrb, module, "dir8", inputDir8, MRB_ARGS_NONE()); mrb_define_module_function(mrb, module, "mouse_x", inputMouseX, MRB_ARGS_NONE()); mrb_define_module_function(mrb, module, "mouse_y", inputMouseY, MRB_ARGS_NONE()); mrb_value modVal = mrb_obj_value(module); if (rgssVer >= 3) { mrb_value symHash = mrb_hash_new_capa(mrb, buttonCodesN); for (size_t i = 0; i < buttonCodesN; ++i) { const char *str = buttonCodes[i].str; mrb_sym sym = mrb_intern_static(mrb, str, strlen(str)); mrb_value symVal = mrb_symbol_value(sym); mrb_value val = mrb_fixnum_value(buttonCodes[i].val); /* In RGSS3 all Input::XYZ constants are equal to :XYZ symbols, * to be compatible with the previous convention */ mrb_const_set(mrb, modVal, sym, symVal); mrb_hash_set(mrb, symHash, symVal, val); } mrb_iv_set(mrb, modVal, mrb_intern_lit(mrb, "buttoncodes"), symHash); getMrbData(mrb)->buttoncodeHash = symHash; } else { for (size_t i = 0; i < buttonCodesN; ++i) { const char *str = buttonCodes[i].str; mrb_sym sym = mrb_intern_static(mrb, str, strlen(str)); mrb_value val = mrb_fixnum_value(buttonCodes[i].val); mrb_const_set(mrb, modVal, sym, val); } } }
void mrb_mruby_uri_parser_gem_init(mrb_state* mrb) { #ifdef _WIN32 WSADATA wsaData; errno = 0; int err = WSAStartup(MAKEWORD(2, 2), &wsaData); if (err != 0) { mrb_sys_fail(mrb, "WSAStartup"); } #endif struct RClass *uri_mod, *uri_error_class; uri_mod = mrb_define_module(mrb, "URI"); uri_error_class = mrb_define_class_under(mrb, uri_mod, "Error", E_RUNTIME_ERROR); mrb_define_class_under(mrb, uri_mod, "Malformed", uri_error_class); mrb_define_class_under(mrb, uri_mod, "HostNotPresent", uri_error_class); mrb_define_class_under(mrb, uri_mod, "HostNotParseable", uri_error_class); mrb_define_class_under(mrb, uri_mod, "ConnectMalformed", uri_error_class); mrb_define_class_under(mrb, uri_mod, "PortTooLarge", uri_error_class); mrb_define_module_function(mrb, uri_mod, "parse", mrb_http_parser_parse_url, MRB_ARGS_ARG(1, 1)); mrb_define_module_function(mrb, uri_mod, "get_port", mrb_uri_parser_get_port, MRB_ARGS_ARG(1, 1)); }
void mrb_mruby_thread_gem_init(mrb_state* mrb) { struct RClass *_class_thread, *_class_mutex, *_class_queue; _class_thread = mrb_define_class(mrb, "Thread", mrb->object_class); MRB_SET_INSTANCE_TT(_class_thread, MRB_TT_DATA); mrb_define_method(mrb, _class_thread, "initialize", mrb_thread_init, MRB_ARGS_OPT(1)); mrb_define_method(mrb, _class_thread, "join", mrb_thread_join, MRB_ARGS_NONE()); mrb_define_method(mrb, _class_thread, "kill", mrb_thread_kill, MRB_ARGS_NONE()); mrb_define_method(mrb, _class_thread, "terminate", mrb_thread_kill, MRB_ARGS_NONE()); mrb_define_method(mrb, _class_thread, "alive?", mrb_thread_alive, MRB_ARGS_NONE()); mrb_define_module_function(mrb, _class_thread, "sleep", mrb_thread_sleep, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, _class_thread, "start", mrb_thread_init, MRB_ARGS_REQ(1)); _class_mutex = mrb_define_class(mrb, "Mutex", mrb->object_class); MRB_SET_INSTANCE_TT(_class_mutex, MRB_TT_DATA); mrb_define_method(mrb, _class_mutex, "initialize", mrb_mutex_init, MRB_ARGS_NONE()); mrb_define_method(mrb, _class_mutex, "lock", mrb_mutex_lock, MRB_ARGS_NONE()); mrb_define_method(mrb, _class_mutex, "try_lock", mrb_mutex_try_lock, MRB_ARGS_NONE()); mrb_define_method(mrb, _class_mutex, "locked?", mrb_mutex_locked, MRB_ARGS_NONE()); mrb_define_method(mrb, _class_mutex, "sleep", mrb_mutex_sleep, MRB_ARGS_REQ(1)); mrb_define_method(mrb, _class_mutex, "synchronize", mrb_mutex_synchronize, MRB_ARGS_REQ(1)); mrb_define_method(mrb, _class_mutex, "unlock", mrb_mutex_unlock, MRB_ARGS_NONE()); _class_queue = mrb_define_class(mrb, "Queue", mrb->object_class); MRB_SET_INSTANCE_TT(_class_queue, MRB_TT_DATA); mrb_define_method(mrb, _class_queue, "initialize", mrb_queue_init, MRB_ARGS_NONE()); mrb_define_method(mrb, _class_queue, "clear", mrb_queue_clear, MRB_ARGS_NONE()); mrb_define_method(mrb, _class_queue, "push", mrb_queue_push, MRB_ARGS_NONE()); mrb_define_alias(mrb, _class_queue, "<<", "push"); mrb_define_method(mrb, _class_queue, "unshift", mrb_queue_unshift, MRB_ARGS_NONE()); mrb_define_alias(mrb, _class_queue, "enq", "unshift"); mrb_define_method(mrb, _class_queue, "pop", mrb_queue_pop, MRB_ARGS_OPT(1)); mrb_define_alias(mrb, _class_queue, "deq", "pop"); mrb_define_method(mrb, _class_queue, "shift", mrb_queue_shift, MRB_ARGS_OPT(1)); mrb_define_method(mrb, _class_queue, "size", mrb_queue_size, MRB_ARGS_NONE()); mrb_define_method(mrb, _class_queue, "num_waiting", mrb_queue_num_waiting, MRB_ARGS_NONE()); mrb_define_method(mrb, _class_queue, "empty?", mrb_queue_empty_p, MRB_ARGS_NONE()); }
//************************************************** // ライブラリを定義します //************************************************** int mp3_Init(mrb_state *mrb,int pausePin, int stopPin) { PausePin = pausePin; StopPin = stopPin; //使用できるピンかどうかチェック if(PausePin == StopPin){ return 0; } if(!chkCanUsePin(PausePin) || !chkCanUsePin(StopPin)){ return 0; } //SDカードが利用可能か確かめます if(!sdcard_Init(mrb)){ return 0; } //インスタンスを作成する前には、強制gcを入れる mrb_full_gc(mrb); //インスタンスを生成します。 if(Wavmp3p == 0){ Wavmp3p = new WavMp3p(44100); } pinMode(PausePin, INPUT_PULLUP); pinMode(StopPin, INPUT_PULLUP); MsTimer2::set(100, cyclic_handler); struct RClass *mp3Module = mrb_define_module(mrb, MP3_CLASS); mrb_define_module_function(mrb, mp3Module, "play", mrb_mp3_play, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, mp3Module, "led", mrb_mp3_led, MRB_ARGS_REQ(1)); return 1; }
void init_mrb_sdl_gl(mrb_state* mrb) { mrb_sdl_gl_class = mrb_define_module(mrb, "GL"); mrb_define_module_function(mrb, mrb_sdl_gl_class, "clear", mrb_sdl_gl_clear, MRB_ARGS_NONE()); mrb_define_module_function(mrb, mrb_sdl_gl_class, "set_clear_color", mrb_sdl_gl_set_clear_color, MRB_ARGS_REQ(3)); mrb_define_module_function(mrb, mrb_sdl_gl_class, "set_clear_flags", mrb_sdl_gl_set_clear_flags, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_sdl_gl_class, "error", mrb_sdl_gl_error, MRB_ARGS_NONE()); mrb_define_module_function(mrb, mrb_sdl_gl_class, "blend_alpha_transparency_without_depth", mrb_sdl_gl_blend_alpha_transparency_without_depth, MRB_ARGS_NONE()); mrb_define_module_function(mrb, mrb_sdl_gl_class, "blend_alpha_transparency", mrb_sdl_gl_blend_alpha_transparency, MRB_ARGS_NONE()); mrb_define_module_function(mrb, mrb_sdl_gl_class, "blend_opaque", mrb_sdl_gl_blend_opaque, MRB_ARGS_NONE()); mrb_define_module_function(mrb, mrb_sdl_gl_class, "viewport", mrb_sdl_gl_viewport, MRB_ARGS_REQ(4)); }
void mrb_mruby_kernel_ext_gem_init(mrb_state *mrb) { struct RClass *krn = mrb->kernel_module; mrb_define_module_function(mrb, krn, "fail", mrb_f_raise, MRB_ARGS_OPT(2)); mrb_define_module_function(mrb, krn, "caller", mrb_f_caller, MRB_ARGS_NONE()); mrb_define_method(mrb, krn, "__method__", mrb_f_method, MRB_ARGS_NONE()); mrb_define_module_function(mrb, krn, "Integer", mrb_f_integer, MRB_ARGS_ANY()); mrb_define_module_function(mrb, krn, "Float", mrb_f_float, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, krn, "String", mrb_f_string, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, krn, "Array", mrb_f_array, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, krn, "Hash", mrb_f_hash, MRB_ARGS_REQ(1)); }
//************************************************** // ライブラリを定義します //************************************************** void i2c_Init(mrb_state *mrb) { //0:Wire1, 1:Wire3, 2:Wire2, 3:Wire6 4:Wire7 RbWire[0] = &Wire1; RbWire[1] = &Wire3; RbWire[2] = &Wire2; RbWire[3] = &Wire6; RbWire[4] = &Wire7; struct RClass *i2cModule = mrb_define_module(mrb, "I2c"); mrb_define_module_function(mrb, i2cModule, "begin", mrb_i2c_begin, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, i2cModule, "write", mrb_i2c_write, MRB_ARGS_REQ(4)); mrb_define_module_function(mrb, i2cModule, "read", mrb_i2c_read, MRB_ARGS_REQ(3)|MRB_ARGS_OPT(1)); mrb_define_module_function(mrb, i2cModule, "begin", mrb_i2c_beginTransmission, MRB_ARGS_REQ(2)); mrb_define_module_function(mrb, i2cModule, "lwrite", mrb_i2c_lwrite, MRB_ARGS_REQ(2)); mrb_define_module_function(mrb, i2cModule, "end", mrb_i2c_endTransmission, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, i2cModule, "request", mrb_i2c_requestFrom, MRB_ARGS_REQ(3)); mrb_define_module_function(mrb, i2cModule, "lread", mrb_i2c_lread, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, i2cModule, "available", mrb_i2c_available, MRB_ARGS_REQ(1)); }
bool init_mruby() { Serial2.println("init_mruby enter"); g_mrb = mrb_open_allocf(myallocfCCM, NULL); // g_mrb = mrb_open_allocf(myallocf, NULL); Serial2.print("mrb_open done. total allocated : "); Serial2.println(total_size, DEC); mrb_load_irep(g_mrb, blinker); RClass *freeRTOSModule = mrb_define_module(g_mrb, "FreeRTOS"); mrb_define_module_function(g_mrb, freeRTOSModule, "sleep", mrb_freertos_sleep, ARGS_REQ(1)); Serial2.println("mruby initialized"); return true; }
void inputBindingInit(mrb_state *mrb) { RClass *module = mrb_define_module(mrb, "Input"); mrb_define_module_function(mrb, module, "update", inputUpdate, MRB_ARGS_NONE()); mrb_define_module_function(mrb, module, "press?", inputPress, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, module, "trigger?", inputTrigger, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, module, "repeat?", inputRepeat, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, module, "dir4", inputDir4, MRB_ARGS_NONE()); mrb_define_module_function(mrb, module, "dir8", inputDir8, MRB_ARGS_NONE()); DEF_CONST_I("DOWN", Input::Down ); DEF_CONST_I("LEFT", Input::Left ); DEF_CONST_I("RIGHT", Input::Right); DEF_CONST_I("UP", Input::Up ); DEF_CONST_I("A", Input::A ); DEF_CONST_I("B", Input::B ); DEF_CONST_I("C", Input::C ); DEF_CONST_I("X", Input::X ); DEF_CONST_I("Y", Input::Y ); DEF_CONST_I("Z", Input::Z ); DEF_CONST_I("L", Input::L ); DEF_CONST_I("R", Input::R ); DEF_CONST_I("SHIFT", Input::Shift); DEF_CONST_I("CTRL", Input::Ctrl ); DEF_CONST_I("ALT", Input::Alt ); DEF_CONST_I("F5", Input::F5 ); DEF_CONST_I("F6", Input::F6 ); DEF_CONST_I("F7", Input::F7 ); DEF_CONST_I("F8", Input::F8 ); DEF_CONST_I("F9", Input::F9 ); mrb_define_module_function(mrb, module, "mouse_x", inputMouseX, MRB_ARGS_NONE()); mrb_define_module_function(mrb, module, "mouse_y", inputMouseY, MRB_ARGS_NONE()); DEF_CONST_I("MOUSELEFT", Input::MouseLeft ); DEF_CONST_I("MOUSEMIDDLE", Input::MouseMiddle); DEF_CONST_I("MOUSERIGHT", Input::MouseRight ); }
void mrb_mruby_thread_gem_init(mrb_state* mrb) { struct RClass *_class_thread, *_class_mutex; _class_thread = mrb_define_class(mrb, "Thread", mrb->object_class); mrb_define_method(mrb, _class_thread, "initialize", mrb_thread_init, ARGS_OPT(1)); mrb_define_method(mrb, _class_thread, "join", mrb_thread_join, ARGS_NONE()); mrb_define_method(mrb, _class_thread, "kill", mrb_thread_kill, ARGS_NONE()); mrb_define_method(mrb, _class_thread, "terminate", mrb_thread_kill, ARGS_NONE()); mrb_define_method(mrb, _class_thread, "alive?", mrb_thread_alive, ARGS_NONE()); mrb_define_module_function(mrb, _class_thread, "sleep", mrb_thread_sleep, ARGS_REQ(1)); _class_mutex = mrb_define_class(mrb, "Mutex", mrb->object_class); mrb_define_method(mrb, _class_mutex, "initialize", mrb_mutex_init, ARGS_NONE()); mrb_define_method(mrb, _class_mutex, "lock", mrb_mutex_lock, ARGS_NONE()); mrb_define_method(mrb, _class_mutex, "try_lock", mrb_mutex_try_lock, ARGS_NONE()); mrb_define_method(mrb, _class_mutex, "locked?", mrb_mutex_locked, ARGS_NONE()); mrb_define_method(mrb, _class_mutex, "sleep", mrb_mutex_sleep, ARGS_REQ(1)); mrb_define_method(mrb, _class_mutex, "synchronize", mrb_mutex_synchronize, ARGS_REQ(1)); mrb_define_method(mrb, _class_mutex, "unlock", mrb_mutex_unlock, ARGS_NONE()); }
//************************************************** // ライブラリを定義します //************************************************** void servo_Init(mrb_state *mrb) { for (int i = 0; i < ATTACH_MAX; i++){ servo[i] = 0; } struct RClass *servoModule = mrb_define_module(mrb, "Servo"); mrb_define_module_function(mrb, servoModule, "attach", mrb_servo_attach, MRB_ARGS_REQ(2) | MRB_ARGS_OPT(2)); mrb_define_module_function(mrb, servoModule, "write", mrb_servo_write, MRB_ARGS_REQ(2)); mrb_define_module_function(mrb, servoModule, "us", mrb_servo_us, MRB_ARGS_REQ(2)); mrb_define_module_function(mrb, servoModule, "read", mrb_servo_read, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, servoModule, "attached", mrb_servo_attached, MRB_ARGS_REQ(1)); mrb_define_module_function(mrb, servoModule, "detach", mrb_servo_detach, MRB_ARGS_REQ(1)); }