void RubyInterpreter::initRuby() { d = new RubyInterpreterPrivate(); ruby_init(); ruby_init_loadpath(); rb_define_global_function("require", (VALUE (*)(...))RubyInterpreter::require, 1); }
int proxenet_ruby_initialize_vm(plugin_t* plugin) { interpreter_t *interpreter; interpreter = plugin->interpreter; /* checks */ if (interpreter->ready) return 0; #ifdef DEBUG xlog(LOG_DEBUG, "Initializing Ruby VM version %s\n", _RUBY_VERSION_); #endif /* init vm */ ruby_init(); interpreter->vm = (void*) rb_mKernel; ruby_script(PROGNAME); ruby_init_loadpath(); interpreter->ready = true; return 0; }
int initrb_start(int argc, char **argv, initrb_boot_fn_t boot) { int ret = 0; { /* Initialize the stack */ RUBY_INIT_STACK; /* Initialize the interpreter */ ruby_init(); /* Initialize the loadpath */ ruby_init_loadpath(); /* We're initrb */ ruby_script("initrb"); /* Set the argv */ ruby_set_argv(argc, argv); /* Boot statics */ initrb_boot_statics(); /* Run */ ret = boot(argc, argv); /* Finalize the interpreter */ ruby_finalize(); } return ret; }
int main(int argc, char *argv[]) { int ret; const char *script = argv[1]; if (script == NULL) { script = //"alphadraw.rb"; "alpha.rb"; //"aadraw.rb"; //"test_fib.rb"; } ruby_debug = Qtrue; ruby_verbose = Qtrue; ruby_init(); ruby_init_loadpath(); ruby_script(script); rb_load_file(script); ret = ruby_cleanup(ruby_exec()); //exit(ret); return(ret); }
int eruta_ruby_init() { VALUE options = Qnil, sublet = Qnil; void Init_prelude(void); RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); ruby_script("eruta"); #ifdef HAVE_RB_ENC_SET_DEFAULT_INTERNAL { VALUE encoding = Qnil; /* FIXME: Fix for ruby 1.9.2p429 borrowed from ruby? */ (void)rb_filesystem_encoding(); /* Set encoding */ encoding = rb_enc_from_encoding(rb_locale_encoding()); rb_enc_set_default_external(encoding); } #endif /* HAVE_RB_ENC_SET_DEFAULT_INTERNAL */ /* FIXME: Fake ruby_init_gems(Qtrue) */ rb_define_module("Gem"); Init_prelude(); /* Bypassing garbage collection. Why? */ /* shelter = rb_ary_new(); rb_gc_register_address(&shelter); */ }
void crb_init() { int argc2 = 0; char **argv2 = NULL; ruby_sysinit(&argc2, &argv2); RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); }
static void * rpmrubyThread(void * _ruby) { rpmruby ruby = _ruby; rpmzLog zlog = ruby->zlog; int i; Trace((zlog, "-- %s: running", __FUNCTION__)); _rpmruby_ruby_to_main(ruby, Qnil); for (i = 0; i < 2; i++) _rpmruby_ruby_to_main(ruby, Qnil); { VALUE variable_in_this_stack_frame; uint8_t * b = ruby->stack; uint8_t * e = b + ruby->nstack; /* Start up the ruby interpreter. */ Trace((zlog, "-- %s: interpreter starting", __FUNCTION__)); ruby_sysinit(&ruby->ac, (char ***) &ruby->av); ruby_bind_stack((VALUE *)b, (VALUE *)e); ruby_init_stack(&variable_in_this_stack_frame); ruby_init(); ruby_init_loadpath(); /* allow Ruby script to relay */ rb_define_module_function(rb_mKernel, "relay_from_ruby_to_main", relay_from_ruby_to_main, 0); Trace((zlog, "-- %s: interpreter started", __FUNCTION__)); /* Run file.rb arguments. */ for (i = 1; i < ruby->ac; i++) { if (*ruby->av[i] == '-') /* XXX FIXME: skip options. */ continue; Trace((zlog, "-- %s: require '%s' begin", __FUNCTION__, ruby->av[i])); rpmrubyRunThreadFile(ruby, ruby->av[i], NULL); Trace((zlog, "-- %s: require '%s' end", __FUNCTION__, ruby->av[i])); } /* Terminate the ruby interpreter. */ Trace((zlog, "-- %s: interpreter terminating", __FUNCTION__)); ruby_finalize(); ruby_cleanup(0); Trace((zlog, "-- %s: interpreter terminated", __FUNCTION__)); } /* Report interpreter end to main. */ ruby->more = 0; /* Permit main thread to run without blocking. */ yarnRelease(ruby->main_coroutine_lock); Trace((zlog, "-- %s: ended", __FUNCTION__)); return NULL; }
void fs_rb_init(int argc, char** argv){ ruby_sysinit(&argc, &argv); RUBY_INIT_STACK ruby_init(); ruby_init_loadpath(); ruby_set_argv(argc, argv); Init_fsnet(); }
void xen_initialize(void) { #ifdef RUBY_INIT_STACK RUBY_INIT_STACK; #endif ruby_init(); ruby_init_loadpath(); ruby_script("xen"); /* necessary in ruby 1.9 (else segfault in rb_raise) */ Init_Hook(); }
int main ( int argc, char ** argv) { ruby_set_debug_option(getenv("RUBY_DEBUG")); ruby_sysinit(&argc, &argv); RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); setbuf(stdout, NULL); // disable buffering rb_protect( test_iseq, 0, & error);// call our stuff rb_protect'ed perror("ERROR"); return ruby_run_node(ruby_options(argc, argv)); ruby_finalize(); return 0; }
int main() { ruby_init(); ruby_init_loadpath(); Init_Dvector(); VALUE cls = rb_eval_string("Dobjects::Dvector"); VALUE res; res = rb_eval_string("Dobjects::Dvector.fast_fancy_read" "(File.open('tmp.dat', 'r'), " "Dobjects::Dvector::FANCY_READ_DEFAULTS)"); return 0; }
int main(int argc, char *argv[]) { void (*sigusr1)(int), (*sigusr2)(int); MPI_Init(&argc, &argv); /* ruby_run() calls exit() (why?), so we have to call finalize this way. */ atexit((void (*)(void))MPI_Finalize); /* Allow errors to be returned as exceptions in ruby */ MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN); /* This seems legitimate because comms can be passed by value to fns. */ self = malloc(sizeof(MPI_Comm)); if (self == NULL) { perror("Unable to allocate MPI::Comm::SELF"); MPI_Finalize(); exit(1); } *self = MPI_COMM_SELF; world = malloc(sizeof(MPI_Comm)); if (self == NULL) { perror("Unable to allocate MPI::Comm::WORLD"); MPI_Finalize(); exit(1); } *world = MPI_COMM_WORLD; MPI_Barrier(*world); sigusr1 = signal(SIGUSR1, SIG_IGN); sigusr2 = signal(SIGUSR2, SIG_IGN); ruby_init(); ruby_init_loadpath(); ruby_options(argc, argv); signal(SIGUSR1, sigusr1); signal(SIGUSR2, sigusr2); MPI_Barrier(*world); Init_MPI(); ruby_run(); /* Unreachable */ MPI_Finalize(); return 0; }
void RubyModule::Initialize() { RubyModule::instance_ = this; ruby_init(); ruby_init_loadpath(); // Add the application directoy to the Ruby include path so // that includes work in a intuitive way for application developers. ruby_incpush(host->GetApplication()->GetResourcesPath().c_str()); this->InitializeBinding(); host->AddModuleProvider(this); }
static void init() { ruby_init(); #if RUBY_VERSION_CODE >= 160 ruby_init_loadpath(); #else #if RUBY_VERSION_CODE >= 145 rb_ary_push(rb_load_path, rb_str_new2(".")); #endif #endif if (eruby_mode == MODE_CGI || eruby_mode == MODE_NPHCGI) rb_set_safe_level(1); eruby_init(); }
/* Called by the epic hooks to activate tcl on-demand. */ void ruby_startstop (int value) { VALUE rubyval; /* If it is already in the state we want, do nothing. */ if (is_ruby_running == value) return; /* Do a shutdown */ if (value == 0) { is_ruby_running = 0; /* Do shutdown stuff */ return; } /* Do a startup */ ++is_ruby_running; ruby_init(); ruby_init_loadpath(); ruby_script(malloc_strdup(irc_version)); rubyclass = rb_define_class("EPIC", rb_cObject); rb_define_singleton_method(rubyclass, "echo", epic_echo, 1); rb_define_singleton_method(rubyclass, "say", epic_say, 1); rb_define_singleton_method(rubyclass, "cmd", epic_cmd, 1); rb_define_singleton_method(rubyclass, "eval", epic_eval, 1); rb_define_singleton_method(rubyclass, "expr", epic_expr, 1); rb_define_singleton_method(rubyclass, "call", epic_call, 1); rb_gc_register_address(&rubyclass); /* XXX Is it a hack to do it like this instead of in pure C? */ rubyval = rb_eval_string("EPICstderr = Object.new unless defined? EPICstderr\n" "def EPICstderr.write(string) \n" " str = string.chomp \n" " EPIC.echo(\"RUBY-ERROR: #{str}\") \n" "end \n" "$stderr = EPICstderr"); if (rubyval == Qnil) say("stderr assignment returned Qnil"); rubyval = rb_eval_string("EPICstdout = Object.new unless defined? EPICstdout\n" "def EPICstdout.write(string) \n" " str = string.chomp \n" " EPIC.echo(str) \n" "end \n" "$stdout = EPICstdout"); if (rubyval == Qnil) say("stderr assignment returned Qnil"); }
int main(int argc, char **argv) { ruby_sysinit(&argc, &argv); { RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); ruby_script("testing!!!!"); rb_gv_set("$brent", ID2SYM(rb_intern("c_defined_symbol"))); int state; rb_protect(require_wrap, 0, &state); } return ruby_cleanup(0); }
void RubyModule::Initialize() { RubyModule::instance_ = this; ruby_init(); ruby_init_loadpath(); // Add the application directoy to the Ruby include path so // that includes work in a intuitive way for application developers. ruby_incpush(UTF8ToSystem(host->GetApplication()->GetResourcesPath()).c_str()); host->script()->AddInterpreter(&interpreter, supportedScriptTypes); host->AddModuleProvider(this); }
int main(int argc, char **argv) { VALUE result; ruby_sysinit(&argc, &argv); RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); rb_require("sum"); // or sum.rb rb_eval_string("$summer = Summer.new"); rb_eval_string("$result = $summer.sum(10)"); result = rb_gv_get("result"); printf("Result = %d\n", NUM2INT(result)); return ruby_cleanup(0); }
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; }
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)); }
static int ensure_ruby_initialized(void) { if (!ruby_initialized) { #ifdef DYNAMIC_RUBY if (ruby_enabled(TRUE)) { #endif #ifdef _WIN32 /* suggested by Ariya Mizutani */ int argc = 1; char *argv[] = {"gvim.exe"}; char **argvp = argv; NtInitialize(&argc, &argvp); #endif { #if defined(RUBY19_OR_LATER) || defined(RUBY_INIT_STACK) ruby_init_stack(ruby_stack_start); #endif ruby_init(); } #ifdef RUBY19_OR_LATER { int dummy_argc = 2; char *dummy_argv[] = {"vim-ruby", "-e0"}; ruby_options(dummy_argc, dummy_argv); } ruby_script("vim-ruby"); #else ruby_init_loadpath(); #endif ruby_io_init(); ruby_vim_init(); ruby_initialized = 1; #ifdef DYNAMIC_RUBY } else { EMSG(_("E266: Sorry, this command is disabled, the Ruby library could not be loaded.")); return 0; } #endif } return ruby_initialized; }
static int init(void *user) { VALUE rb_RadareCmd; ruby_init(); ruby_init_loadpath(); rb_eval_string_protect("require 'irb'", NULL); core = user; rb_RadareCmd = rb_define_class("RadareInternal", rb_cObject); rb_define_method(rb_RadareCmd, "cmd", radare_ruby_cmd, 1); rb_eval_string_protect("$r = RadareInternal.new()", NULL); if (!slurp_ruby(RUBYAPI)) { printf("[ruby] error loading ruby api\n"); //return R_FALSE; } return R_TRUE; }
int policy_init( const Pool *p ) { ruby_init(); ruby_init_loadpath(); rb_set_safe_level(0); //FIXME /* give the ruby code a name */ ruby_script("satsolver_policy"); cPolicy = rb_define_class( "SatPolicy", rb_cObject ); /* load the policy implementation */ rb_require( "satsolver_policy" ); pool = p; return 0; }
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); }
// keep on looking at the modification date of the file 'embed.rb' and eval it if it changes int main () { time_t test_mod_time = 0; struct stat attrib; int load_function_sym; VALUE file_name; VALUE loader; int count = 0; // register stop_running signal( SIGINT, stop_running ); ruby_init(); ruby_init_loadpath(); ruby_script("rubyk"); rb_require("embed_loader.rb"); file_name = rb_str_new2("embed.rb"); loader = rb_class_new_instance(0,0,rb_const_get(rb_cObject, rb_intern("Loader"))); load_function_sym = rb_intern("secure_load"); running = 1; while(running) { sleep(0.1); count = count + 1; // get attributes stat("embed.rb", &attrib); if (test_mod_time != attrib.st_mtime) { printf("Finally a change (%i)\n", count); count = 0; test_mod_time = attrib.st_mtime; rb_funcall(loader, load_function_sym, 1, file_name); } } printf("\nbye...\n"); ruby_finalize(); exit(0); }
void startup(const char* script_name) { if(running) { return; } int fake_argc = 0; char *fake_args[fake_argc]; char **fake_argv = fake_args; ruby_sysinit(&fake_argc, &fake_argv); // Initialize Ruby itself RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); //Init_prelude(); //ruby_init_gems(); // To load prelude.rb static char* args[] = { "ruby", "/dev/null" }; ruby_process_options(2, args); // Load Ruby encodings, otherwise we'll get all kinds of "Unitialized // constanct Encoding::UTF-7", etc. everywhere. rb_enc_find_index("encdb"); VALUE gem; gem = rb_define_module("Gem"); rb_const_set(gem, rb_intern("Enable"), Qtrue); rb_require("rubygems"); ruby_script((char*)script_name); running = true; }
int main() { // 1. init interpreter ruby_init(); ruby_init_loadpath(); //ruby_script("embed.rb"); // 2. load global objects Init_SysInfo(); // 3. run script // int state = eval_buffer("puts \"kamin babo\"\nprint $hardware"); // int state = eval_file("/Users/yielding/test/rb/embed/embed.rb"); int state = eval_file("embed.rb"); if (state) printf("error\n"); print_array(hardware_list); // 4. finalize // ruby_finalize(); ruby_cleanup(0); }
int main(int argc, char *argv[]) { int i; for(i=0; i <= argc - 1; ++i) { printf("%s", argv[i]); } ruby_sysinit(&argc, &argv); { RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); VALUE array = rb_ary_new2(argc); for(i=0; i <= argc - 1; ++i) { rb_ary_push(array, rb_str_new2(argv[i])); } rb_funcall(Qnil, rb_intern("require"), 1, rb_str_new2("./libcef-test.rb")); rb_funcall(Qnil, rb_intern("run"), 1, array); } return 0; }
static int RbGlobalInitialize(const CMPIBroker* broker, CMPIStatus* st) { char *loadpath; VALUE searchpath; _SBLIM_TRACE(1,("<%d> Ruby: RbGlobalInitialize, stack @ %p", getpid(), &searchpath)); ruby_init(); ruby_init_loadpath(); extern void SWIG_init(); SWIG_init(); searchpath = rb_gv_get("$:"); /* Append /usr/share/cmpi to $: */ rb_ary_push(searchpath, rb_str_new2("/usr/share/cmpi")); /* Check RUBY_PROVIDERS_DIR_ENV if its a dir, append to $: */ loadpath = getenv(RUBY_PROVIDERS_DIR_ENV); if (loadpath) { struct stat buf; if (stat(loadpath, &buf)) { _SBLIM_TRACE(1,("<%d> Can't stat $%s '%s'", getpid(), RUBY_PROVIDERS_DIR_ENV, loadpath)); return -1; } if ((buf.st_mode & S_IFDIR) == 0) { _SBLIM_TRACE(1,("<%d> Not a directory: $%s '%s'", getpid(), RUBY_PROVIDERS_DIR_ENV, loadpath)); return -1; } _SBLIM_TRACE(1,("<%d> Loading providers from: $%s '%s'", getpid(), RUBY_PROVIDERS_DIR_ENV, loadpath)); rb_ary_push(searchpath, rb_str_new2(loadpath)); } else { _SBLIM_TRACE(0, ("<%d> Hmm, %s not set ?!", getpid(), RUBY_PROVIDERS_DIR_ENV)); } return 0; }