void Init_load(void) { #undef rb_intern #define rb_intern(str) rb_intern2((str), strlen(str)) rb_vm_t *vm = GET_VM(); static const char var_load_path[] = "$:"; ID id_load_path = rb_intern2(var_load_path, sizeof(var_load_path)-1); rb_define_hooked_variable(var_load_path, (VALUE*)vm, load_path_getter, rb_gvar_readonly_setter); rb_alias_variable(rb_intern("$-I"), id_load_path); rb_alias_variable(rb_intern("$LOAD_PATH"), id_load_path); vm->load_path = rb_ary_new(); vm->expanded_load_path = rb_ary_tmp_new(0); vm->load_path_snapshot = rb_ary_tmp_new(0); vm->load_path_check_cache = 0; rb_define_virtual_variable("$\"", get_loaded_features, 0); rb_define_virtual_variable("$LOADED_FEATURES", get_loaded_features, 0); vm->loaded_features = rb_ary_new(); vm->loaded_features_snapshot = rb_ary_tmp_new(0); vm->loaded_features_index = st_init_strtable(); rb_define_global_function("load", rb_f_load, -1); rb_define_global_function("require", rb_f_require, 1); rb_define_global_function("require_relative", rb_f_require_relative, 1); rb_define_method(rb_cModule, "autoload", rb_mod_autoload, 2); rb_define_method(rb_cModule, "autoload?", rb_mod_autoload_p, 1); rb_define_global_function("autoload", rb_f_autoload, 2); rb_define_global_function("autoload?", rb_f_autoload_p, 1); ruby_dln_librefs = rb_ary_tmp_new(0); rb_gc_register_mark_object(ruby_dln_librefs); }
void Init_RhoSupport() { rb_define_global_function("require", rb_require_compiled, 1); rb_define_global_function("eval_compiled_file", rb_f_eval_compiled, -1); rb_define_global_function("__rhoGetCurrentDir", __rhoGetCurrentDir, 0); rb_define_global_function("load", rb_require_compiled, 1); Init_RhoLog(); Init_RhoBlobs(); }
/* --- */ int init_ruby_parser(void) { ruby_init(); rb_define_global_function("get_row", get_row, 0); rb_define_global_function("get_col", get_col, 0); return ruby_interpreter = register_interpreter("Ruby", NULL, execute_ruby); }
void Init_RhoSupport() { rb_RhoModule = 0; rb_RhoJSON = 0; rb_RhoLogModule = 0; rb_RhoStdoutClass = 0; rb_RhoProfilerModule = 0; rb_RhoMessages = 0; rb_RhoError = 0; get_message_mid = 0; err_message_mid = 0; rb_define_global_function("require", rb_require_compiled, 1); #ifndef RHODES_EMULATOR rb_define_global_function("eval_compiled_file", rb_f_eval_compiled, -1); #else rb_define_global_function("__rhoGetRhodesDir", __rhoGetRhodesDir, 0); #endif rb_define_global_function("__rhoGetCurrentDir", __rhoGetCurrentDir, 0); rb_define_global_function("__rhoGetRuntimeDir", __rhoGetRuntimeDir, 0); rb_define_global_function("__rhoGetUserDir", __rhoGetUserDir, 0); rb_define_global_function("__rhoGetDBDir", __rhoGetDBDir, 0); rb_define_global_function("load", rb_load_compiled, 1); rb_define_global_function("__rhoGetCallbackObject", __rhoGetCallbackObject, 1); rb_define_method(rb_mKernel, "rhom_init", rb_obj_rhom_init, 1); Init_RhoLog(); Init_RhoBlobs(); Init_RhoJSON(); }
void Init_RhoSupport() { rb_define_global_function("require", rb_require_compiled, 1); rb_define_global_function("eval_compiled_file", rb_f_eval_compiled, -1); rb_define_global_function("__rhoGetCurrentDir", __rhoGetCurrentDir, 0); rb_define_global_function("load", rb_require_compiled, 1); rb_define_global_function("__rhoGetCallbackObject", __rhoGetCallbackObject, 1); rb_define_method(rb_mKernel, "rhom_init", rb_obj_rhom_init, 1); Init_RhoLog(); Init_RhoBlobs(); }
void Init_vm_eval(void) { rb_define_global_function("eval", rb_f_eval, -1); rb_define_global_function("local_variables", rb_f_local_variables, 0); rb_define_global_function("iterator?", rb_f_block_given_p, 0); rb_define_global_function("block_given?", rb_f_block_given_p, 0); rb_define_global_function("catch", rb_f_catch, -1); rb_define_global_function("throw", rb_f_throw, -1); rb_define_global_function("loop", rb_f_loop, 0); rb_define_method(rb_cBasicObject, "instance_eval", rb_obj_instance_eval, -1); rb_define_method(rb_cBasicObject, "instance_exec", rb_obj_instance_exec, -1); rb_define_private_method(rb_cBasicObject, "method_missing", rb_method_missing, -1); rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1); rb_define_method(rb_mKernel, "send", rb_f_send, -1); rb_define_method(rb_mKernel, "public_send", rb_f_public_send, -1); rb_define_method(rb_cModule, "module_exec", rb_mod_module_exec, -1); rb_define_method(rb_cModule, "class_exec", rb_mod_module_exec, -1); rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1); rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1); rb_define_global_function("caller", rb_f_caller, -1); }
void RubyInterpreter::initRuby() { d = new RubyInterpreterPrivate(); ruby_init(); ruby_init_loadpath(); rb_define_global_function("require", (VALUE (*)(...))RubyInterpreter::require, 1); }
void Init_Exception() { rb_eException = rb_define_class("Exception", rb_cObject); rb_define_singleton_method(rb_eException, "exception", rb_class_new_instance, -1); rb_define_method(rb_eException, "exception", exc_exception, -1); rb_define_method(rb_eException, "initialize", exc_initialize, -1); rb_define_method(rb_eException, "to_s", exc_to_s, 0); rb_define_method(rb_eException, "to_str", exc_to_str, 0); rb_define_method(rb_eException, "message", exc_to_str, 0); rb_define_method(rb_eException, "inspect", exc_inspect, 0); rb_define_method(rb_eException, "backtrace", exc_backtrace, 0); rb_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1); rb_eSystemExit = rb_define_class("SystemExit", rb_eException); rb_define_method(rb_eSystemExit, "initialize", exit_initialize, -1); rb_define_method(rb_eSystemExit, "status", exit_status, 0); rb_define_method(rb_eSystemExit, "success?", exit_success_p, 0); rb_eFatal = rb_define_class("fatal", rb_eException); rb_eSignal = rb_define_class("SignalException", rb_eException); rb_eInterrupt = rb_define_class("Interrupt", rb_eSignal); rb_eStandardError = rb_define_class("StandardError", rb_eException); rb_eTypeError = rb_define_class("TypeError", rb_eStandardError); rb_eArgError = rb_define_class("ArgumentError", rb_eStandardError); rb_eIndexError = rb_define_class("IndexError", rb_eStandardError); rb_eRangeError = rb_define_class("RangeError", rb_eStandardError); rb_eNameError = rb_define_class("NameError", rb_eStandardError); rb_define_method(rb_eNameError, "initialize", name_err_initialize, -1); rb_define_method(rb_eNameError, "name", name_err_name, 0); rb_define_method(rb_eNameError, "to_s", name_err_to_s, 0); rb_cNameErrorMesg = rb_define_class_under(rb_eNameError, "message", rb_cData); rb_define_singleton_method(rb_cNameErrorMesg, "!", name_err_mesg_new, 3); rb_define_method(rb_cNameErrorMesg, "to_str", name_err_mesg_to_str, 0); rb_define_method(rb_cNameErrorMesg, "_dump", name_err_mesg_to_str, 1); rb_define_singleton_method(rb_cNameErrorMesg, "_load", name_err_mesg_load, 1); rb_eNoMethodError = rb_define_class("NoMethodError", rb_eNameError); rb_define_method(rb_eNoMethodError, "initialize", nometh_err_initialize, -1); rb_define_method(rb_eNoMethodError, "args", nometh_err_args, 0); rb_eScriptError = rb_define_class("ScriptError", rb_eException); rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError); rb_eLoadError = rb_define_class("LoadError", rb_eScriptError); rb_eNotImpError = rb_define_class("NotImplementedError", rb_eScriptError); rb_eRuntimeError = rb_define_class("RuntimeError", rb_eStandardError); rb_eSecurityError = rb_define_class("SecurityError", rb_eStandardError); rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException); syserr_tbl = st_init_numtable(); rb_eSystemCallError = rb_define_class("SystemCallError", rb_eStandardError); rb_define_method(rb_eSystemCallError, "initialize", syserr_initialize, -1); rb_define_method(rb_eSystemCallError, "errno", syserr_errno, 0); rb_define_singleton_method(rb_eSystemCallError, "===", syserr_eqq, 1); rb_mErrno = rb_define_module("Errno"); rb_define_global_function("warn", rb_warn_m, 1); }
int main(int argc, char **argv) { int nRes = 0; #ifdef RUBY_DEBUG_ENV ruby_set_debug_option(getenv("RUBY_DEBUG")); #endif #ifdef HAVE_LOCALE_H setlocale(LC_CTYPE, ""); #endif // MessageBox(0,"","",MB_OK); ruby_sysinit(&argc, &argv); { RUBY_INIT_STACK; ruby_init(); Init_strscan(); Init_sqlite3_api(); Init_SyncEngine(); Init_System(); //Init_prelude(); rb_define_global_function("__rho_compile", __rho_compile, 1); nRes = ruby_run_node(ruby_options(argc, argv)); } return nRes; }
static void define_function_rb(language_t*li, const char*name, function_t*f) { rb_internal_t*rb = (rb_internal_t*)li->internal; log_dbg("[ruby] define function %s", name); rb_define_global_function(name, ruby_function_proxy, -2); store_function(name, f); }
void Init_module_spec() { VALUE cls, mod; cls = rb_define_class("CApiModuleSpecs", rb_cObject); rb_define_method(cls, "rb_const_set", module_specs_const_set, 3); rb_define_method(cls, "rb_const_get", module_specs_const_get, 2); rb_define_method(cls, "rb_const_get_from", module_specs_const_get_from, 2); rb_define_method(cls, "rb_const_get_at", module_specs_const_get_at, 2); rb_define_method(cls, "rb_define_const", module_specs_define_const, 3); rb_define_method(cls, "rb_define_global_const", module_specs_define_global_const, 2); rb_define_method(cls, "rb_const_defined", module_specs_const_defined, 2); rb_define_method(cls, "rb_const_defined_at", module_specs_const_defined_at, 2); cls = rb_define_class("CApiDefineAliasSpecs", rb_cObject); rb_define_method(cls, "rb_define_alias", sa_define_alias, 3); cls = rb_define_class("CApiMethodVisSpecs", rb_cObject); mod = rb_define_module("CApiMethodVisModule"); rb_define_method(cls, "smv_test_public", smv_test, 0); rb_define_protected_method(cls, "smv_test_protected", smv_test, 0); rb_define_private_method(cls, "smv_test_private", smv_test, 0); rb_define_singleton_method(mod, "smv_test_singleton", smv_test, 0); rb_define_module_function(mod, "smv_test_module_function", smv_test, 0); rb_define_global_function("smv_test_global_function", smv_test, 0); rb_define_method(cls, "rb_undef_method", smv_undef_method, 2); }
/* * Many operating systems allow signals to be sent to running * processes. Some signals have a defined effect on the process, while * others may be trapped at the code level and acted upon. For * example, your process may trap the USR1 signal and use it to toggle * debugging, and may use TERM to initiate a controlled shutdown. * * pid = fork do * Signal.trap("USR1") do * $debug = !$debug * puts "Debug now: #$debug" * end * Signal.trap("TERM") do * puts "Terminating..." * shutdown() * end * # . . . do some work . . . * end * * Process.detach(pid) * * # Controlling program: * Process.kill("USR1", pid) * # ... * Process.kill("USR1", pid) * # ... * Process.kill("TERM", pid) * * produces: * Debug now: true * Debug now: false * Terminating... * * The list of available signal names and their interpretation is * system dependent. Signal delivery semantics may also vary between * systems; in particular signal delivery may not always be reliable. */ void Init_signal(void) { VALUE mSignal = rb_define_module("Signal"); rb_define_global_function("trap", sig_trap, -1); rb_define_module_function(mSignal, "trap", sig_trap, -1); rb_define_module_function(mSignal, "list", sig_list, 0); rb_define_method(rb_eSignal, "initialize", esignal_init, -1); rb_define_method(rb_eSignal, "signo", esignal_signo, 0); rb_alias(rb_eSignal, rb_intern("signm"), rb_intern("message")); rb_define_method(rb_eInterrupt, "initialize", interrupt_init, -1); install_sighandler(SIGINT, sighandler); #ifdef SIGHUP install_sighandler(SIGHUP, sighandler); #endif #ifdef SIGQUIT install_sighandler(SIGQUIT, sighandler); #endif #ifdef SIGTERM install_sighandler(SIGTERM, sighandler); #endif #ifdef SIGALRM install_sighandler(SIGALRM, sighandler); #endif #ifdef SIGUSR1 install_sighandler(SIGUSR1, sighandler); #endif #ifdef SIGUSR2 install_sighandler(SIGUSR2, sighandler); #endif #ifdef RUBY_DEBUG_ENV if (!ruby_enable_coredump) #endif { #ifdef SIGBUS install_sighandler(SIGBUS, sigbus); #endif #ifdef SIGSEGV # ifdef USE_SIGALTSTACK rb_register_sigaltstack(GET_THREAD()); # endif install_sighandler(SIGSEGV, (sighandler_t)sigsegv); #endif } #ifdef SIGPIPE install_sighandler(SIGPIPE, sigpipe); #endif #if defined(SIGCLD) init_sigchld(SIGCLD); #elif defined(SIGCHLD) init_sigchld(SIGCHLD); #endif }
/* * Many operating systems allow signals to be sent to running * processes. Some signals have a defined effect on the process, while * others may be trapped at the code level and acted upon. For * example, your process may trap the USR1 signal and use it to toggle * debugging, and may use TERM to initiate a controlled shutdown. * * pid = fork do * Signal.trap("USR1") do * $debug = !$debug * puts "Debug now: #$debug" * end * Signal.trap("TERM") do * puts "Terminating..." * shutdown() * end * # . . . do some work . . . * end * * Process.detach(pid) * * # Controlling program: * Process.kill("USR1", pid) * # ... * Process.kill("USR1", pid) * # ... * Process.kill("TERM", pid) * * produces: * Debug now: true * Debug now: false * Terminating... * * The list of available signal names and their interpretation is * system dependent. Signal delivery semantics may also vary between * systems; in particular signal delivery may not always be reliable. */ void Init_signal(void) { #ifndef MACOS_UNUSE_SIGNAL VALUE mSignal = rb_define_module("Signal"); rb_define_global_function("trap", sig_trap, -1); rb_define_module_function(mSignal, "trap", sig_trap, -1); rb_define_module_function(mSignal, "list", sig_list, 0); rb_define_method(rb_eSignal, "initialize", esignal_init, -1); rb_attr(rb_eSignal, rb_intern("signo"), 1, 0, 0); rb_alias(rb_eSignal, rb_intern("signm"), rb_intern("message")); rb_define_method(rb_eInterrupt, "initialize", interrupt_init, -1); install_sighandler(SIGINT, sighandler); #ifdef SIGHUP install_sighandler(SIGHUP, sighandler); #endif #ifdef SIGQUIT install_sighandler(SIGQUIT, sighandler); #endif #ifdef SIGTERM install_sighandler(SIGTERM, sighandler); #endif #ifdef SIGALRM install_sighandler(SIGALRM, sighandler); #endif #ifdef SIGUSR1 install_sighandler(SIGUSR1, sighandler); #endif #ifdef SIGUSR2 install_sighandler(SIGUSR2, sighandler); #endif #ifdef RUBY_DEBUG_ENV if (!ruby_enable_coredump) #endif { #ifdef SIGBUS install_sighandler(SIGBUS, sigbus); #endif #ifdef SIGSEGV install_sighandler(SIGSEGV, sigsegv); #endif } #ifdef SIGPIPE install_sighandler(SIGPIPE, sigpipe); #endif #if defined(SIGCLD) init_sigchld(SIGCLD); #elif defined(SIGCHLD) init_sigchld(SIGCHLD); #endif #endif /* MACOS_UNUSE_SIGNAL */ }
void Init_guess() { rb_define_method(rb_cString, "guess_encoding", guess4r_str__guess_encoding, 0); rb_define_method(rb_cString, "guess!", guess4r_str__guess_bang, 0); rb_define_method(rb_cString, "guess", guess4r_str__guess, 0); rb_define_global_function("guess_open", guess4r_f__guess_open, -1); rb_ivar_set(rb_cEncoding, rb_intern("guess_region"), rb_str_new2(GUESS_REGION_DEFAULT)); rb_define_singleton_method(rb_cEncoding, "guess_region", guess4r_enc__guess_region, 0); rb_define_singleton_method(rb_cEncoding, "guess_region=", guess4r_enc__guess_region_set, 1); }
void Init_clockcount() { VALUE mClockCount; mClockCount = rb_define_module("ClockCount"); rb_define_const(mClockCount, "CLOCKCOUNT_BITS", INT2FIX(CLOCKCOUNT_BITS)); rb_define_global_function("ClockCount", clockcount_m, 0); }
void Init_hijack(void) { VALUE proc; rb_define_global_function("hijack", f_hijack, 0); proc = rb_eval_string("lambda {}"); blk_mark = (void (*)(struct BLOCK*)) RDATA(proc)->dmark; blk_free = (void (*)(struct BLOCK*)) RDATA(proc)->dfree; }
void ruby_Init_Continuation_body(void) { rb_cContinuation = rb_define_class("Continuation", rb_cObject); rb_undef_alloc_func(rb_cContinuation); rb_undef_method(CLASS_OF(rb_cContinuation), "new"); rb_define_method(rb_cContinuation, "call", rb_cont_call, -1); rb_define_method(rb_cContinuation, "[]", rb_cont_call, -1); rb_define_global_function("callcc", rb_callcc, 0); }
void Init_Binding(void) { rb_cBinding = rb_define_class("Binding", rb_cObject); rb_undef_alloc_func(rb_cBinding); rb_undef_method(CLASS_OF(rb_cBinding), "new"); rb_define_method(rb_cBinding, "clone", binding_clone, 0); rb_define_method(rb_cBinding, "dup", binding_dup, 0); rb_define_method(rb_cBinding, "eval", bind_eval, -1); rb_define_global_function("binding", rb_f_binding, 0); }
/* load the interpreter and the script */ void startup_myruby(void) { int rc; RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); /* dumps the version info to stdout */ ruby_show_version(); /* set working dir for includes */ rb_eval_string_protect("$: << '.'", &rc); /* NOTRANSLATE */ #if USE_RUBYVERSION < 19 #else rb_enc_find_index("encdb"); /* NOTRANSLATE */ #endif myruby_loaded = 0; //define that callback below rb_define_global_function("iroffer_input", cie_inputline, 0); /* NOTRANSLATE */ rb_define_global_function("iroffer_privmsg", cie_privmsg, 2); /* NOTRANSLATE */ Init_IrofferEvent(); load_script(gdata.ruby_script); }
void Init_pairwize() { rb_define_global_function("say_hello", say_hello, 0); rb_define_global_function("hello1", hello1, 1); rb_define_global_function("hello2", hello2, 2); rb_define_global_function("pairwize_force", pairwize_force, 3); RCbody = rb_define_class("Cbody", rb_cObject); rb_define_singleton_method(RCbody, "new", Cbody_new, 0); rb_define_method(RCbody, "set_mass", RCbody_set_mass, 1); rb_define_method(RCbody, "get_mass", RCbody_get_mass, 0); rb_define_method(RCbody, "set_pos_vel_and_mass", RCbody_set_pos_vel_and_mass, 1); rb_define_method(RCbody, "set_acc_jerk", RCbody_set_acc_jerk, 1); rb_define_method(RCbody, "get_acc_jerk", RCbody_get_acc_jerk, 1); rb_define_method(RCbody, "set_epot_and_collq", Cbody_set_epot_and_collq, 1); rb_define_method(RCbody, "get_epot_and_collq", Cbody_get_epot_and_collq, 1); rb_define_method(RCbody, "pairwize_force", RCbody_pairwize_force, 1); rb_define_method(RCbody, "copy_to_c", RCbody_copy_to_C, 1); rb_define_method(RCbody, "copy_from_c", RCbody_copy_from_C, 1); rb_define_method(RCbody, "clear_acc_and_jerk", RCbody_clear_acc_and_jerk, 0); rb_define_method(RCbody, "set_dt", set_dt, 1); rb_define_method(RCbody, "predict", predict, 0); rb_define_method(RCbody, "correct", correct, 0); rb_define_method(RCbody, "update_old", RCbody_update_old, 0); rb_define_global_function("Cbody_calculate_force_all", Cbody_calculate_force_all,2); }
static void rb_w_define_klass() { /* * Initialize Ruby Interpreter */ int rb_argc = 0; char *rb_argv[] = {NULL}; ruby_init(); ruby_init_loadpath(); ruby_options(rb_argc, rb_argv); ruby_script("Wireplay"); /* * Initialize the Wireplay::Hook class for ruby hook repository */ rb_mWireplay = rb_define_module("Wireplay"); rb_const_set(rb_mWireplay, rb_intern("WIREPLAY_PROG_NAME"), rb_str_new2(WIREPLAY_PROG_NAME)); rb_const_set(rb_mWireplay, rb_intern("WIREPLAY_PROG_VER"), rb_str_new2(WIREPLAY_PROG_VER)); //rb_const_set(rb_mWireplay, rb_intern("WIREPLAY_AUTHOR"), rb_str_new2(WIREPLAY_AUTHOR)); rb_const_set(rb_mWireplay, rb_intern("WIREPLAY_COPYRIGHT"), rb_str_new2(WIREPLAY_COPYRIGHT)); rb_const_set(rb_mWireplay, rb_intern("REPLAY_SERVER_TO_CLIENT"), INT2FIX(REPLAY_SERVER_TO_CLIENT)); rb_const_set(rb_mWireplay, rb_intern("REPLAY_CLIENT_TO_SERVER"), INT2FIX(REPLAY_CLIENT_TO_SERVER)); rb_const_set(rb_mWireplay, rb_intern("ERROR_CONNECT_FAILED"), INT2FIX(ERROR_CONNECT_FAILED)); rb_const_set(rb_mWireplay, rb_intern("ERROR_SEND_FAILED"), INT2FIX(ERROR_SEND_FAILED)); rb_const_set(rb_mWireplay, rb_intern("ERROR_RECV_FAILED"), INT2FIX(ERROR_RECV_FAILED)); rb_const_set(rb_mWireplay, rb_intern("ERROR_TIMEOUT"), INT2FIX(ERROR_TIMEOUT)); rb_const_set(rb_mWireplay, rb_intern("ERROR_SOCKET_ERROR"), INT2FIX(ERROR_SOCKET_ERROR)); rb_const_set(rb_mWireplay, rb_intern("ROLE_CLIENT"), INT2FIX(ROLE_CLIENT)); rb_const_set(rb_mWireplay, rb_intern("ROLE_SERVER"), INT2FIX(ROLE_SERVER)); rb_define_global_function("cmsg", rb_w_cmsg, 1); /* TODO: define other msg.c functions */ rb_cHook = rb_define_class_under(rb_mWireplay, "Hooks", rb_cObject); rb_cvar_set(rb_cHook, rb_intern("_hooks"), rb_ary_new(), 0); rb_define_singleton_method(rb_cHook, "register", rb_cHook_register, 1); rb_define_singleton_method(rb_cHook, "hooks", rb_cHook_hooks, 0); rb_define_singleton_method(rb_mWireplay, "start_irb", rb_test_start_irb, 0); rb_define_singleton_method(rb_mWireplay, "load_library", rb_mWireplay_load_library, 1); //rb_test_start_irb(); return; }
/* * Many operating systems allow signals to be sent to running * processes. Some signals have a defined effect on the process, while * others may be trapped at the code level and acted upon. For * example, your process may trap the USR1 signal and use it to toggle * debugging, and may use TERM to initiate a controlled shutdown. * * pid = fork do * Signal.trap("USR1") do * $debug = !$debug * puts "Debug now: #$debug" * end * Signal.trap("TERM") do * puts "Terminating..." * shutdown() * end * # . . . do some work . . . * end * * Process.detach(pid) * * # Controlling program: * Process.kill("USR1", pid) * # ... * Process.kill("USR1", pid) * # ... * Process.kill("TERM", pid) * * produces: * Debug now: true * Debug now: false * Terminating... * * The list of available signal names and their interpretation is * system dependent. Signal delivery semantics may also vary between * systems; in particular signal delivery may not always be reliable. */ void Init_signal(void) { #ifndef MACOS_UNUSE_SIGNAL VALUE mSignal = rb_define_module("Signal"); rb_define_global_function("trap", sig_trap, -1); rb_define_module_function(mSignal, "trap", sig_trap, -1); rb_define_module_function(mSignal, "list", sig_list, 0); install_sighandler(SIGINT, sighandler); #ifdef SIGHUP install_sighandler(SIGHUP, sighandler); #endif #ifdef SIGQUIT install_sighandler(SIGQUIT, sighandler); #endif #ifdef SIGTERM install_sighandler(SIGTERM, sighandler); #endif #ifdef SIGALRM install_sighandler(SIGALRM, sighandler); #endif #ifdef SIGUSR1 install_sighandler(SIGUSR1, sighandler); #endif #ifdef SIGUSR2 install_sighandler(SIGUSR2, sighandler); #endif #ifdef SIGBUS install_sighandler(SIGBUS, sigbus); #endif #ifdef SIGSEGV install_sighandler(SIGSEGV, sigsegv); #endif #ifdef SIGPIPE install_sighandler(SIGPIPE, sigpipe); #endif #if defined(SIGCLD) init_sigchld(SIGCLD); #elif defined(SIGCHLD) init_sigchld(SIGCHLD); #endif #endif /* MACOS_UNUSE_SIGNAL */ }
static int mod_init(lua_State *l) { int ret = ruby_setup(); if (ret != 0) { return luaL_error(l, "ruby_setup: %d", ret); } ruby_init_loadpath(); rb_define_global_function("rwrite", api_rwrite, 2); // VALUE api = rb_define_module("Api"); // rb_define_module_function(api, "rwrite", api_rwrite, 0); // rb_define_const(mRUBBER, "TestConst", INT2NUM(38)); return 0; }
static void init( MessageHandler *handler) { VALUE load_path; InitMONFUNC(RubyConv, JSON_PackValue, JSON_UnPackValue, JSON_SizeValue); ruby_init(); ruby_init_loadpath(); load_path = rb_eval_string("$LOAD_PATH"); if (handler->loadpath == NULL) { handler->loadpath = getenv("APS_RUBY_PATH"); } if (handler->loadpath == NULL) { handler->loadpath = getenv("RUBYLIB"); } if (handler->loadpath == NULL) { handler->loadpath = MONTSUQI_LOAD_PATH; } rb_ary_push(load_path, rb_str_new2(handler->loadpath)); application_classes = rb_hash_new(); rb_gc_register_address(&application_classes); rb_global_variable(&application_classes); node_info = rb_hash_new(); rb_gc_register_address(&node_info); rb_global_variable(&node_info); rb_define_global_function("monfunc", monfunc, 2); rb_define_global_const("MCP_OK" ,INT2NUM(MCP_OK)); rb_define_global_const("MCP_EOF" ,INT2NUM(MCP_EOF)); rb_define_global_const("MCP_NONFATAL" ,INT2NUM(MCP_NONFATAL)); rb_define_global_const("MCP_BAD_ARG" ,INT2NUM(MCP_BAD_ARG)); rb_define_global_const("MCP_BAD_FUNC" ,INT2NUM(MCP_BAD_FUNC)); rb_define_global_const("MCP_BAD_OTHER" ,INT2NUM(MCP_BAD_OTHER)); rb_define_global_const("MCP_BAD_CONN" ,INT2NUM(MCP_BAD_CONN)); }
void Init_rbpod(void) { /* This is the wrapper for all RbPod related classes. */ mRbPod = rb_define_module("RbPod"); Init_rbpod_error(); Init_rbpod_database(); Init_rbpod_device(); Init_rbpod_collection(); Init_rbpod_playlist(); Init_rbpod_playlist_collection(); Init_rbpod_track(); Init_rbpod_track_collection(); rb_define_global_function("RbPod", rbpod_load_database, 1); rb_cPathname = rb_const_get(rb_cObject, rb_intern("Pathname")); return; }
void init_ruby(struct module *module) { unsigned char *path; /* Set up and initialize the interpreter. This function should be called * before any other Ruby-related functions. */ ruby_init(); ruby_script("ELinks-ruby"); ruby_init_loadpath(); /* ``Trap'' debug prints from scripts. */ rb_define_singleton_method(rb_stdout, "write", erb_module_message, 1); rb_define_global_function("p", erb_stdout_p, -1); /* Set up the ELinks module interface. */ init_erb_module(); if (elinks_home) { path = straconcat(elinks_home, RUBY_HOOKS_FILENAME, (unsigned char *) NULL); } else { path = stracpy(CONFDIR STRING_DIR_SEP RUBY_HOOKS_FILENAME); } if (!path) return; if (file_can_read(path)) { int error; /* Load ~/.elinks/hooks.rb into the interpreter. */ //rb_load_file(path); rb_load_protect(rb_str_new2(path), 0, &error); if (error) erb_report_error(NULL, error); } mem_free(path); }
int main(int argc, char **argv) { int nRes = 0; //_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_CRT_DF | _CRTDBG_LEAK_CHECK_DF); #ifdef RUBY_DEBUG_ENV ruby_set_debug_option(getenv("RUBY_DEBUG")); #endif #ifdef HAVE_LOCALE_H setlocale(LC_CTYPE, ""); #endif #ifdef WIN32 SetEnvironmentVariable("RUBYOPT",""); SetEnvironmentVariable("RUBYLIB",""); #endif //WIN32 // MessageBox(0,"","",MB_OK); ruby_sysinit(&argc, &argv); { RUBY_INIT_STACK; ruby_init(); Init_strscan(); //Init_sqlite3_api(); Init_SyncEngine(); Init_System(); //Init_prelude(); rb_define_global_function("__rho_compile", __rho_compile, 1); nRes = ruby_run_node(ruby_options(argc, argv)); } return nRes; }
/* This function is called from inits.c */ void Init_vm_trace(void) { /* trace_func */ rb_define_global_function("set_trace_func", set_trace_func, 1); rb_define_method(rb_cThread, "set_trace_func", thread_set_trace_func_m, 1); rb_define_method(rb_cThread, "add_trace_func", thread_add_trace_func_m, 1); /* * Document-class: TracePoint * * A class that provides the functionality of Kernel#set_trace_func in a * nice Object-Oriented API. * * == Example * * We can use TracePoint to gather information specifically for exceptions: * * trace = TracePoint.new(:raise) do |tp| * p [tp.lineno, tp.event, tp.raised_exception] * end * #=> #<TracePoint:0x007f786a452448> * * trace.enable * #=> #<TracePoint:0x007f786a452448> * * 0 / 0 * #=> [5, :raise, #<ZeroDivisionError: divided by 0>] * * == Events * * If you don't specify the type of events you want to listen for, * TracePoint will include all available events. * * *Note* do not depend on current event set, as this list is subject to * change. Instead, it is recommended you specify the type of events you * want to use. * * To filter what is traced, you can pass any of the following as +events+: * * +:line+:: execute code on a new line * +:class+:: start a class or module definition * +:end+:: finish a class or module definition * +:call+:: call a Ruby method * +:return+:: return from a Ruby method * +:c_call+:: call a C-language routine * +:c_return+:: return from a C-language routine * +:raise+:: raise an exception * +:b_call+:: event hook at block entry * +:b_return+:: event hook at block ending * +:thread_begin+:: event hook at thread beginning * +:thread_end+:: event hook at thread ending * */ rb_cTracePoint = rb_define_class("TracePoint", rb_cObject); rb_undef_alloc_func(rb_cTracePoint); rb_undef_method(CLASS_OF(rb_cTracePoint), "new"); rb_define_singleton_method(rb_cTracePoint, "new", tracepoint_new_s, -1); /* * Document-method: trace * * call-seq: * TracePoint.trace(*events) { |obj| block } -> obj * * A convenience method for TracePoint.new, that activates the trace * automatically. * * trace = TracePoint.trace(:call) { |tp| [tp.lineno, tp.event] } * #=> #<TracePoint:0x007f786a452448> * * trace.enabled? #=> true */ rb_define_singleton_method(rb_cTracePoint, "trace", tracepoint_trace_s, -1); rb_define_method(rb_cTracePoint, "enable", tracepoint_enable_m, 0); rb_define_method(rb_cTracePoint, "disable", tracepoint_disable_m, 0); rb_define_method(rb_cTracePoint, "enabled?", rb_tracepoint_enabled_p, 0); rb_define_method(rb_cTracePoint, "inspect", tracepoint_inspect, 0); rb_define_method(rb_cTracePoint, "event", tracepoint_attr_event, 0); rb_define_method(rb_cTracePoint, "lineno", tracepoint_attr_lineno, 0); rb_define_method(rb_cTracePoint, "path", tracepoint_attr_path, 0); rb_define_method(rb_cTracePoint, "method_id", tracepoint_attr_method_id, 0); rb_define_method(rb_cTracePoint, "defined_class", tracepoint_attr_defined_class, 0); rb_define_method(rb_cTracePoint, "binding", tracepoint_attr_binding, 0); rb_define_method(rb_cTracePoint, "self", tracepoint_attr_self, 0); rb_define_method(rb_cTracePoint, "return_value", tracepoint_attr_return_value, 0); rb_define_method(rb_cTracePoint, "raised_exception", tracepoint_attr_raised_exception, 0); }
/* * A complex number can be represented as a paired real number with * imaginary unit; a+bi. Where a is real part, b is imaginary part * and i is imaginary unit. Real a equals complex a+0i * mathematically. * * In ruby, you can create complex object with Complex, Complex::rect, * Complex::polar or to_c method. * * Complex(1) #=> (1+0i) * Complex(2, 3) #=> (2+3i) * Complex.polar(2, 3) #=> (-1.9799849932008908+0.2822400161197344i) * 3.to_c #=> (3+0i) * * You can also create complex object from floating-point numbers or * strings. * * Complex(0.3) #=> (0.3+0i) * Complex('0.3-0.5i') #=> (0.3-0.5i) * Complex('2/3+3/4i') #=> ((2/3)+(3/4)*i) * Complex('1@2') #=> (-0.4161468365471424+0.9092974268256817i) * * 0.3.to_c #=> (0.3+0i) * '0.3-0.5i'.to_c #=> (0.3-0.5i) * '2/3+3/4i'.to_c #=> ((2/3)+(3/4)*i) * '1@2'.to_c #=> (-0.4161468365471424+0.9092974268256817i) * * A complex object is either an exact or an inexact number. * * Complex(1, 1) / 2 #=> ((1/2)+(1/2)*i) * Complex(1, 1) / 2.0 #=> (0.5+0.5i) */ void Init_Complex(void) { VALUE compat; #undef rb_intern #define rb_intern(str) rb_intern_const(str) assert(fprintf(stderr, "assert() is now active\n")); id_abs = rb_intern("abs"); id_arg = rb_intern("arg"); id_convert = rb_intern("convert"); id_denominator = rb_intern("denominator"); id_eqeq_p = rb_intern("=="); id_expt = rb_intern("**"); id_fdiv = rb_intern("fdiv"); id_negate = rb_intern("-@"); id_numerator = rb_intern("numerator"); id_quo = rb_intern("quo"); id_real_p = rb_intern("real?"); id_to_f = rb_intern("to_f"); id_to_i = rb_intern("to_i"); id_to_r = rb_intern("to_r"); id_i_real = rb_intern("@real"); id_i_imag = rb_intern("@image"); /* @image, not @imag */ rb_cComplex = rb_define_class("Complex", rb_cNumeric); rb_define_alloc_func(rb_cComplex, nucomp_s_alloc); rb_undef_method(CLASS_OF(rb_cComplex), "allocate"); #if 0 rb_define_private_method(CLASS_OF(rb_cComplex), "new!", nucomp_s_new_bang, -1); rb_define_private_method(CLASS_OF(rb_cComplex), "new", nucomp_s_new, -1); #else rb_undef_method(CLASS_OF(rb_cComplex), "new"); #endif rb_define_singleton_method(rb_cComplex, "rectangular", nucomp_s_new, -1); rb_define_singleton_method(rb_cComplex, "rect", nucomp_s_new, -1); rb_define_singleton_method(rb_cComplex, "polar", nucomp_s_polar, -1); rb_define_global_function("Complex", nucomp_f_complex, -1); rb_undef_method(rb_cComplex, "%"); rb_undef_method(rb_cComplex, "<"); rb_undef_method(rb_cComplex, "<="); rb_undef_method(rb_cComplex, "<=>"); rb_undef_method(rb_cComplex, ">"); rb_undef_method(rb_cComplex, ">="); rb_undef_method(rb_cComplex, "between?"); rb_undef_method(rb_cComplex, "div"); rb_undef_method(rb_cComplex, "divmod"); rb_undef_method(rb_cComplex, "floor"); rb_undef_method(rb_cComplex, "ceil"); rb_undef_method(rb_cComplex, "modulo"); rb_undef_method(rb_cComplex, "remainder"); rb_undef_method(rb_cComplex, "round"); rb_undef_method(rb_cComplex, "step"); rb_undef_method(rb_cComplex, "truncate"); rb_undef_method(rb_cComplex, "i"); rb_define_method(rb_cComplex, "real", nucomp_real, 0); rb_define_method(rb_cComplex, "imaginary", nucomp_imag, 0); rb_define_method(rb_cComplex, "imag", nucomp_imag, 0); rb_define_method(rb_cComplex, "-@", nucomp_negate, 0); rb_define_method(rb_cComplex, "+", nucomp_add, 1); rb_define_method(rb_cComplex, "-", nucomp_sub, 1); rb_define_method(rb_cComplex, "*", nucomp_mul, 1); rb_define_method(rb_cComplex, "/", nucomp_div, 1); rb_define_method(rb_cComplex, "quo", nucomp_quo, 1); rb_define_method(rb_cComplex, "fdiv", nucomp_fdiv, 1); rb_define_method(rb_cComplex, "**", nucomp_expt, 1); rb_define_method(rb_cComplex, "==", nucomp_eqeq_p, 1); rb_define_method(rb_cComplex, "coerce", nucomp_coerce, 1); rb_define_method(rb_cComplex, "abs", nucomp_abs, 0); rb_define_method(rb_cComplex, "magnitude", nucomp_abs, 0); rb_define_method(rb_cComplex, "abs2", nucomp_abs2, 0); rb_define_method(rb_cComplex, "arg", nucomp_arg, 0); rb_define_method(rb_cComplex, "angle", nucomp_arg, 0); rb_define_method(rb_cComplex, "phase", nucomp_arg, 0); rb_define_method(rb_cComplex, "rectangular", nucomp_rect, 0); rb_define_method(rb_cComplex, "rect", nucomp_rect, 0); rb_define_method(rb_cComplex, "polar", nucomp_polar, 0); rb_define_method(rb_cComplex, "conjugate", nucomp_conj, 0); rb_define_method(rb_cComplex, "conj", nucomp_conj, 0); #if 0 rb_define_method(rb_cComplex, "~", nucomp_conj, 0); /* gcc */ #endif rb_define_method(rb_cComplex, "real?", nucomp_false, 0); #if 0 rb_define_method(rb_cComplex, "complex?", nucomp_true, 0); rb_define_method(rb_cComplex, "exact?", nucomp_exact_p, 0); rb_define_method(rb_cComplex, "inexact?", nucomp_inexact_p, 0); #endif rb_define_method(rb_cComplex, "numerator", nucomp_numerator, 0); rb_define_method(rb_cComplex, "denominator", nucomp_denominator, 0); rb_define_method(rb_cComplex, "hash", nucomp_hash, 0); rb_define_method(rb_cComplex, "eql?", nucomp_eql_p, 1); rb_define_method(rb_cComplex, "to_s", nucomp_to_s, 0); rb_define_method(rb_cComplex, "inspect", nucomp_inspect, 0); rb_define_private_method(rb_cComplex, "marshal_dump", nucomp_marshal_dump, 0); compat = rb_define_class_under(rb_cComplex, "compatible", rb_cObject); /* :nodoc: */ rb_define_private_method(compat, "marshal_load", nucomp_marshal_load, 1); rb_marshal_define_compat(rb_cComplex, compat, nucomp_dumper, nucomp_loader); /* --- */ rb_define_method(rb_cComplex, "to_i", nucomp_to_i, 0); rb_define_method(rb_cComplex, "to_f", nucomp_to_f, 0); rb_define_method(rb_cComplex, "to_r", nucomp_to_r, 0); rb_define_method(rb_cComplex, "rationalize", nucomp_rationalize, -1); rb_define_method(rb_cComplex, "to_c", nucomp_to_c, 0); rb_define_method(rb_cNilClass, "to_c", nilclass_to_c, 0); rb_define_method(rb_cNumeric, "to_c", numeric_to_c, 0); rb_define_method(rb_cString, "to_c", string_to_c, 0); rb_define_private_method(CLASS_OF(rb_cComplex), "convert", nucomp_s_convert, -1); /* --- */ rb_define_method(rb_cNumeric, "real", numeric_real, 0); rb_define_method(rb_cNumeric, "imaginary", numeric_imag, 0); rb_define_method(rb_cNumeric, "imag", numeric_imag, 0); rb_define_method(rb_cNumeric, "abs2", numeric_abs2, 0); rb_define_method(rb_cNumeric, "arg", numeric_arg, 0); rb_define_method(rb_cNumeric, "angle", numeric_arg, 0); rb_define_method(rb_cNumeric, "phase", numeric_arg, 0); rb_define_method(rb_cNumeric, "rectangular", numeric_rect, 0); rb_define_method(rb_cNumeric, "rect", numeric_rect, 0); rb_define_method(rb_cNumeric, "polar", numeric_polar, 0); rb_define_method(rb_cNumeric, "conjugate", numeric_conj, 0); rb_define_method(rb_cNumeric, "conj", numeric_conj, 0); rb_define_method(rb_cFloat, "arg", float_arg, 0); rb_define_method(rb_cFloat, "angle", float_arg, 0); rb_define_method(rb_cFloat, "phase", float_arg, 0); /* * The imaginary unit. */ rb_define_const(rb_cComplex, "I", f_complex_new_bang2(rb_cComplex, ZERO, ONE)); rb_provide("complex.so"); /* for backward compatibility */ }
void Init_Exception(void) { rb_eException = rb_define_class("Exception", rb_cObject); rb_define_singleton_method(rb_eException, "exception", rb_class_new_instance, -1); rb_define_method(rb_eException, "exception", exc_exception, -1); rb_define_method(rb_eException, "initialize", exc_initialize, -1); rb_define_method(rb_eException, "==", exc_equal, 1); rb_define_method(rb_eException, "to_s", exc_to_s, 0); rb_define_method(rb_eException, "message", exc_message, 0); rb_define_method(rb_eException, "inspect", exc_inspect, 0); rb_define_method(rb_eException, "backtrace", exc_backtrace, 0); rb_define_method(rb_eException, "backtrace_locations", exc_backtrace_locations, 0); rb_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1); rb_define_method(rb_eException, "cause", exc_cause, 0); rb_eSystemExit = rb_define_class("SystemExit", rb_eException); rb_define_method(rb_eSystemExit, "initialize", exit_initialize, -1); rb_define_method(rb_eSystemExit, "status", exit_status, 0); rb_define_method(rb_eSystemExit, "success?", exit_success_p, 0); rb_eFatal = rb_define_class("fatal", rb_eException); rb_eSignal = rb_define_class("SignalException", rb_eException); rb_eInterrupt = rb_define_class("Interrupt", rb_eSignal); rb_eStandardError = rb_define_class("StandardError", rb_eException); rb_eTypeError = rb_define_class("TypeError", rb_eStandardError); rb_eArgError = rb_define_class("ArgumentError", rb_eStandardError); rb_eIndexError = rb_define_class("IndexError", rb_eStandardError); rb_eKeyError = rb_define_class("KeyError", rb_eIndexError); rb_eRangeError = rb_define_class("RangeError", rb_eStandardError); rb_eScriptError = rb_define_class("ScriptError", rb_eException); rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError); rb_eLoadError = rb_define_class("LoadError", rb_eScriptError); /* the path failed to load */ rb_attr(rb_eLoadError, rb_intern_const("path"), 1, 0, Qfalse); rb_eNotImpError = rb_define_class("NotImplementedError", rb_eScriptError); rb_eNameError = rb_define_class("NameError", rb_eStandardError); rb_define_method(rb_eNameError, "initialize", name_err_initialize, -1); rb_define_method(rb_eNameError, "name", name_err_name, 0); rb_cNameErrorMesg = rb_define_class_under(rb_eNameError, "message", rb_cData); rb_define_singleton_method(rb_cNameErrorMesg, "!", rb_name_err_mesg_new, NAME_ERR_MESG_COUNT); rb_define_method(rb_cNameErrorMesg, "==", name_err_mesg_equal, 1); rb_define_method(rb_cNameErrorMesg, "to_str", name_err_mesg_to_str, 0); rb_define_method(rb_cNameErrorMesg, "_dump", name_err_mesg_dump, 1); rb_define_singleton_method(rb_cNameErrorMesg, "_load", name_err_mesg_load, 1); rb_eNoMethodError = rb_define_class("NoMethodError", rb_eNameError); rb_define_method(rb_eNoMethodError, "initialize", nometh_err_initialize, -1); rb_define_method(rb_eNoMethodError, "args", nometh_err_args, 0); rb_eRuntimeError = rb_define_class("RuntimeError", rb_eStandardError); rb_eSecurityError = rb_define_class("SecurityError", rb_eException); rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException); rb_eEncodingError = rb_define_class("EncodingError", rb_eStandardError); rb_eEncCompatError = rb_define_class_under(rb_cEncoding, "CompatibilityError", rb_eEncodingError); syserr_tbl = st_init_numtable(); rb_eSystemCallError = rb_define_class("SystemCallError", rb_eStandardError); rb_define_method(rb_eSystemCallError, "initialize", syserr_initialize, -1); rb_define_method(rb_eSystemCallError, "errno", syserr_errno, 0); rb_define_singleton_method(rb_eSystemCallError, "===", syserr_eqq, 1); rb_mErrno = rb_define_module("Errno"); rb_define_global_function("warn", rb_warn_m, -1); }