int main(int argc, char **argv, char **envp) { #ifdef HAVE_LOCALE_H setlocale(LC_CTYPE, ""); #endif ruby_is_miniruby = argc > 0 && strstr(argv[0], "miniruby") != NULL; try { ruby_sysinit(&argc, &argv); ruby_init(); void *node = ruby_options(argc, argv); rb_vm_init_compiler(); if (ruby_aot_compile) { rb_vm_aot_compile((NODE *)node); rb_exit(0); } else { rb_exit(ruby_run_node(node)); } } catch (...) { rb_vm_print_current_exception(); rb_exit(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 mriBindingExecute() { /* Normally only a ruby executable would do a sysinit, * but not doing it will lead to crashes due to closed * stdio streams on some platforms (eg. Windows) */ int argc = 0; char **argv = 0; ruby_sysinit(&argc, &argv); ruby_setup(); rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding())); Config &conf = shState->rtData().config; if (!conf.rubyLoadpaths.empty()) { /* Setup custom load paths */ VALUE lpaths = rb_gv_get(":"); for (size_t i = 0; i < conf.rubyLoadpaths.size(); ++i) { std::string &path = conf.rubyLoadpaths[i]; VALUE pathv = rb_str_new(path.c_str(), path.size()); rb_ary_push(lpaths, pathv); } } RbData rbData; shState->setBindingData(&rbData); BacktraceData btData; mriBindingInit(); STEAMSHIM_init(); _rb_define_module_function(rb_mKernel, "_steam_achievement_unlock", _steamAchievementUnlock); std::string &customScript = conf.customScript; if (!customScript.empty()) runCustomScript(customScript); else runRMXPScripts(btData); VALUE exc = rb_errinfo(); if (!NIL_P(exc) && !rb_obj_is_kind_of(exc, rb_eSystemExit)) showExc(exc, btData); ruby_cleanup(0); STEAMSHIM_deinit(); shState->rtData().rqTermAck.set(); }
int main(int argc, char **argv) { // MessageBox(0,"","",MB_OK); ruby_sysinit(&argc, &argv); RhoRubyStart(); RhoRubyStop(); }
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; }
int main(int argc, char **argv) { ruby_sysinit(&argc, &argv); { RUBY_INIT_STACK; ruby_init(); return ruby_run_node(ruby_options(argc, argv)); } }
void boot_vm() { _argc = 0; _argv = &gorby; ruby_sysinit(&_argc, &_argv); { RUBY_INIT_STACK; ruby_init(); } }
void crb_init() { int argc2 = 0; char **argv2 = NULL; ruby_sysinit(&argc2, &argv2); RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); }
int main(int argc, char **argv) { int i; int myargc; char** myargv; char script_path[MAXPATHLEN]; char* dump_val; DWORD attr; #ifdef HAVE_LOCALE_H setlocale(LC_CTYPE, ""); #endif dump_val = getenv("EXEFY_DUMP"); if (GetModuleFileName(NULL, script_path, MAXPATHLEN)) { for (i = strlen(script_path) - 1; i >= 0; --i) { if (*(script_path + i) == '.') { *(script_path + i) = '\0'; break; } } attr = GetFileAttributes(script_path); if (attr == INVALID_FILE_ATTRIBUTES) { printf("Script %s is missing!", script_path); return -1; } // Let Ruby initialize program arguments ruby_sysinit(&argc, &argv); // Change arguments by inserting path to script file // as second argument (first argument is always executable // name) and copying arguments from command line after it. myargc = argc + 1; myargv = (char**)xmalloc(sizeof(char*) * (myargc + 1)); memset(myargv, 0, sizeof(char*) * (myargc + 1)); *myargv = *argv; *(myargv + 1) = &script_path[0]; for (i = 1; i < argc; ++i) { *(myargv + i + 1) = *(argv + i); } if (NULL != dump_val) { dump_args(myargc, myargv); } { RUBY_INIT_STACK; ruby_init(); return ruby_run_node(ruby_options(myargc, myargv)); } } }
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(); }
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 nacl_main(int argc, char **argv) { if (nacl_startup_untar(argv[0], DATA_ARCHIVE, "/")) return -1; if (argc == 2 && !strcmp(argv[1], "/bin/irb")) fprintf(stderr, "Launching irb ...\n"); ruby_sysinit(&argc, &argv); { RUBY_INIT_STACK; ruby_init(); return ruby_run_node(ruby_options(argc, argv)); } }
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); }
int shoes_ruby_embed() { VALUE v; char *argv[] = {"ruby", "-e", "1"}; int sysinit_argc = 0; char** sysinit_argv = NULL; RUBY_INIT_STACK; #ifdef SHOES_WIN32 ruby_sysinit( &sysinit_argc, &sysinit_argv ); #endif ruby_init(); v = (VALUE)ruby_options(3, argv); return !FIXNUM_P(v); }
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 CRScriptCore::InitializeEnvironment() { ATLTRACE(_("Initialize Environment in Thread:%08X\n"), GetCurrentThreadId()); #ifndef __IRubyEngine_INTERFACE_DEFINED__ int stacktop; s_pStackTop = reinterpret_cast<LPBYTE>(&stacktop); #endif int dummyargc(1); char* dummyargv[] = {"dummy", NULL }; char** pargv; ruby_sysinit(&dummyargc, &pargv); RUBY_INIT_STACK; ruby_init(); ruby_options(3, asr_argv); s_pEncoding = rb_default_internal_encoding(); if (!s_pEncoding) s_pEncoding = rb_default_external_encoding(); try { rb_require("win32ole"); VALUE v = rb_eval_string("WIN32OLE"); // override original constructor rb_define_singleton_method(v, "new", reinterpret_cast<VALUE(*)(...)>(fole_s_new), -1); rb_define_singleton_method(v, "connect", reinterpret_cast<VALUE(*)(...)>(fole_s_connect), 1); rb_define_singleton_method(v, "attach", reinterpret_cast<VALUE(*)(...)>(foleex_attach), 2); rb_define_method(v, "__release", reinterpret_cast<VALUE(*)(...)>(foleex_release), 0); rb_define_method(v, "method_missing", reinterpret_cast<VALUE(*)(...)>(foleex_missing), -1); rb_define_method(v, "each", reinterpret_cast<VALUE(*)(...)>(foleex_each), 0); if (rb_const_defined_at(v, rb_intern("ARGV")) == Qfalse) { rb_define_const(v, "ARGV", rb_ary_new()); } s_valueWin32Ole = v; s_valueWIN32OLERuntimeError = rb_eval_string("WIN32OLERuntimeError"); v = rb_define_class("WIN32OLEEX", v); s_valueWin32OleEx = v; rb_define_singleton_method(v, "attach", reinterpret_cast<VALUE(*)(...)>(foleex_attach), 2); rb_define_method(v, "method_missing", reinterpret_cast<VALUE(*)(...)>(foleex_missing), -1); // s_valueActiveRubyScript = rb_define_class("ActiveScriptRuby", rb_cObject); rb_define_singleton_method(s_valueActiveRubyScript, "trace", (VALUE(*)(...))trace_hook, 6); rb_define_singleton_method(s_valueActiveRubyScript, "settrace", (VALUE(*)(...))trace_set, 1); rb_define_singleton_method(s_valueActiveRubyScript, "rubyize", (VALUE(*)(...))rubyize, 1); } catch (...) { ATLTRACE(_T("Exception for class\n")); } }
int main(int argc, char **argv) { #ifdef RUBY_DEBUG_ENV ruby_set_debug_option(getenv("RUBY_DEBUG")); #endif #ifdef HAVE_LOCALE_H setlocale(LC_CTYPE, ""); #endif ruby_sysinit(&argc, &argv); { RUBY_INIT_STACK; ruby_init(); return ruby_run_node(ruby_options(argc, argv)); } }
int main(void) { char *argv_raw[] = { "milter-manager", "-e", "''" }; int argc; char **argv; argc = sizeof(argv_raw) / sizeof(char *); argv = argv_raw; ruby_sysinit(&argc, &argv); { RUBY_INIT_STACK; ruby_init(); return ruby_run_node(ruby_process_options(argc, argv)); } }
void stub_sysinit(int *argc, char ***argv) { WCHAR exename[4096]; size_t wlenexe, len0, lenall; int lenexe; int i, ac; char **av, *p; wlenexe = (size_t)GetModuleFileNameW(NULL, exename, sizeof(exename) / sizeof(*exename)); lenexe = WideCharToMultiByte(CP_UTF8, 0, exename, wlenexe, NULL, 0, NULL, NULL); ruby_sysinit(argc, argv); ac = *argc; av = *argv; len0 = strlen(av[0]) + 1; lenall = 0; for (i = 1; i < ac; ++i) { lenall += strlen(av[i]) + 1; } av = realloc(av, lenall + len0 + (lenexe + 1) + sizeof(char *) * (i + 2)); if (!av) { perror("realloc command line"); exit(-1); } *argv = av; *argc = ++ac; p = (char *)(av + i + 2); memmove(p + len0 + lenexe + 1, (char *)(av + ac) + len0, lenall); memmove(p, (char *)(av + ac), len0); *av++ = p; p += len0; WideCharToMultiByte(CP_UTF8, 0, exename, wlenexe, p, lenexe, NULL, NULL); p[lenexe] = '\0'; *av++ = p; p += lenexe + 1; while (--i) { *av++ = p; p += strlen(p) + 1; } *av = NULL; }
void stub_sysinit(int *argc, char ***argv) { char exename[4096]; size_t lenexe, len0, lenall; int i, ac; char **av, *p; lenexe = (size_t)GetModuleFileName(NULL, exename, sizeof exename); ruby_sysinit(argc, argv); ac = *argc; av = *argv; len0 = strlen(av[0]) + 1; lenall = 0; for (i = 1; i < ac; ++i) { lenall += strlen(av[i]) + 1; } av = realloc(av, lenall + (lenexe + 1) * 2 + sizeof(char *) * (i + 2)); if (!av) { perror("realloc command line"); exit(-1); } *argv = av; *argc = ++ac; p = (char *)(av + i + 2); memmove(p + (lenexe + 1) * 2, (char *)(av + ac) + len0, lenall); memcpy(p, exename, lenexe); p[lenexe] = '\0'; *av++ = p; p += lenexe + 1; memcpy(p, exename, lenexe); p[lenexe] = '\0'; *av++ = p; p += lenexe + 1; while (--i) { *av++ = p; p += strlen(p) + 1; } *av = NULL; }
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; }
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(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; }
/** * Load a Ruby file then run the function corresponding to the service by * passing the conf, inputs and outputs parameters by refernce as Ruby Hash. * * @param main_conf the conf maps containing the main.cfg settings * @param request the map containing the HTTP request * @param s the service structure * @param real_inputs the maps containing the inputs * @param real_outputs the maps containing the outputs * @return SERVICE_SUCCEEDED or SERVICE_FAILED if the service run, -1 * if the service failed to load or throw error at runtime. */ int zoo_ruby_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){ #if RUBY_API_VERSION_MAJOR >= 2 || RUBY_API_VERSION_MINOR == 9 ruby_sysinit(&argc,&argv); RUBY_INIT_STACK; #endif ruby_init(); maps* m=*main_conf; maps* inputs=*real_inputs; maps* outputs=*real_outputs; map* tmp0=getMapFromMaps(*main_conf,"lenv","cwd"); char *ntmp=tmp0->value; map* tmp=NULL; ruby_init_loadpath(); ruby_script("ZOO_EMBEDDED_ENV"); VALUE klass=rb_define_module("Zoo"); rb_define_const(klass,"SERVICE_SUCCEEDED",INT2FIX(3)); rb_define_const(klass,"SERVICE_FAILED",INT2FIX(4)); typedef VALUE (*HOOK)(...); rb_define_module_function(klass,"Translate",reinterpret_cast<HOOK>(RubyTranslate),-1); rb_define_module_function(klass,"UpdateStatus",reinterpret_cast<HOOK>(RubyUpdateStatus),-1); int error = 0; ID rFunc=Qnil; tmp=getMap(s->content,"serviceProvider"); if(tmp!=NULL){ #if RUBY_VERSION_MINOR == 8 const char* script = ruby_sourcefile = rb_source_filename(tmp->value); rb_protect(LoadWrap, reinterpret_cast<VALUE>(script), &error); #else rb_load_protect(rb_str_new2(tmp->value), 0, &error); #endif if(error) { ruby_trace_error(m); return -1; } #if RUBY_VERSION_MINOR == 8 ruby_exec(); #else ruby_exec_node(NULL); #endif } else{ map* err=createMap("text","Unable to parse serviceProvider please check your zcfg file."); addToMap(err,"code","NoApplicableCode"); printExceptionReportResponse(m,err); return -1; } int res=SERVICE_FAILED; rFunc=rb_intern(s->name); if(rFunc!=Qnil){ VALUE arg1=RubyHash_FromMaps(m); VALUE arg2=RubyHash_FromMaps(inputs); VALUE arg3=RubyHash_FromMaps(outputs); VALUE rArgs[3]={arg1,arg2,arg3}; if (!rArgs) return -1; struct my_callback data; data.obj=Qnil; data.method_id=rFunc; data.nargs=3; data.args[0]=rArgs[0]; data.args[1]=rArgs[1]; data.args[2]=rArgs[2]; typedef VALUE (*HOOK)(VALUE); VALUE tres=rb_protect(reinterpret_cast<HOOK>(FunCallWrap),(VALUE)(&data),&error); if (TYPE(tres) == T_FIXNUM) { res=FIX2INT(tres); freeMaps(real_outputs); free(*real_outputs); freeMaps(main_conf); free(*main_conf); *main_conf=mapsFromRubyHash(arg1); *real_outputs=mapsFromRubyHash(arg3); #ifdef DEBUG dumpMaps(*main_conf); dumpMaps(*real_outputs); #endif }else{ ruby_trace_error(m); res=-1; } } else{ char tmpS[1024]; sprintf(tmpS, "Cannot find the %s function in the %s file.\n", s->name, tmp->value); map* tmps=createMap("text",tmpS); printExceptionReportResponse(m,tmps); res=-1; } ruby_finalize(); return res; }
rpmruby rpmrubyNew(char ** av, uint32_t flags) { static char * _av[] = { "rpmruby", NULL }; rpmruby ruby = (flags & 0x80000000) ? rpmrubyI() : rpmrubyGetPool(_rpmrubyPool); int xx; RUBYDBG((stderr, "--> %s(%p,0x%x) ruby %p\n", __FUNCTION__, av, flags, ruby)); /* If failure, or retrieving already initialized _rpmrubyI, just exit. */ if (ruby == NULL || ruby == _rpmrubyI) goto exit; if (av == NULL) av = _av; ruby->flags = flags; xx = argvAppend(&ruby->av, (ARGV_t)av); ruby->ac = argvCount(ruby->av); /* XXX FIXME: 0x40000000 => xruby.c wrapper without interpreter. */ if (ruby->flags & 0x40000000) { static size_t _rpmrubyStackSize = 4 * 1024 * 1024; /* XXX save as global interpreter. */ _rpmrubyI = ruby; ruby->nstack = _rpmrubyStackSize; ruby->stack = malloc(ruby->nstack); assert(ruby->stack != NULL); gettimeofday(&ruby->start, NULL); /* starting time for log entries */ if (_rpmruby_debug) ruby->zlog = rpmzLogNew(&ruby->start); /* initialize logging */ /* initialize the relay mechanism */ ruby->ruby_coroutine_lock = yarnNewLock(0); ruby->main_coroutine_lock = yarnNewLock(0); } else { #if defined(WITH_RUBYEMBED) VALUE variable_in_this_stack_frame; /* RUBY_INIT_STSCK */ #if defined(HAVE_RUBY_DEFINES_H) /* XXX ruby-1.9.2 */ ruby_sysinit(&ruby->ac, (char ***) &ruby->av); /* XXX ruby-1.9.2p0 ruby_bind_stack() patch needed */ { uint8_t * b = ruby->stack; uint8_t * e = b + ruby->nstack; ruby_bind_stack((VALUE *)b, (VALUE *) e); } #endif /* NOTYET */ ruby_init_stack(&variable_in_this_stack_frame); /* RUBY_INIT_STACK */ ruby_init(); ruby_init_loadpath(); ruby_script((char *)av[0]); if (av[1]) ruby_set_argv(argvCount((ARGV_t)av)-1, av+1); rb_gv_set("$result", rb_str_new2("")); #if !defined(HAVE_RUBY_DEFINES_H) /* XXX ruby-1.8.6 */ (void) rpmrubyRun(ruby, rpmrubyInitStringIO, NULL); #endif #endif /* WITH_RUBYEMBED */ } exit: return rpmrubyLink(ruby); }
int main(int argc, char *argv[]) { ruby_sysinit(&argc, &argv); { RUBY_INIT_STACK; ruby_init(); } #if _DEBUG || (__GNUC__ && !NDEBUG) #ifdef _WIN32 const char *logfilepath = "./openstudio_pat.log"; #else const char *logfilepath = "/var/log/openstudio_pat.log"; #endif openstudio::Logger::instance().standardOutLogger().setLogLevel(Debug); openstudio::FileLogSink fileLog(openstudio::toPath(logfilepath)); fileLog.setLogLevel(Debug); #else openstudio::Logger::instance().standardOutLogger().setLogLevel(Warn); #endif // list of Ruby modules we want to load into the interpreter std::vector<std::string> modules; modules.push_back("openstudioutilitiescore"); modules.push_back("openstudioutilitiesbcl"); modules.push_back("openstudioutilitiesidd"); modules.push_back("openstudioutilitiesidf"); modules.push_back("openstudioutilities"); modules.push_back("openstudiomodel"); modules.push_back("openstudiomodelcore"); modules.push_back("openstudiomodelsimulation"); modules.push_back("openstudiomodelresources"); modules.push_back("openstudiomodelgeometry"); modules.push_back("openstudiomodelhvac"); modules.push_back("openstudiomodelrefrigeration"); modules.push_back("openstudioenergyplus"); modules.push_back("openstudioruleset"); bool cont = true; while(cont) { cont = false; // Initialize the embedded Ruby interpreter std::shared_ptr<openstudio::detail::RubyInterpreter> rubyInterpreter( new openstudio::detail::RubyInterpreter(openstudio::getOpenStudioRubyPath(), openstudio::getOpenStudioRubyScriptsPath(), modules)); // Initialize the argument getter QSharedPointer<openstudio::ruleset::RubyUserScriptInfoGetter> infoGetter( new openstudio::ruleset::EmbeddedRubyUserScriptInfoGetter<openstudio::detail::RubyInterpreter>(rubyInterpreter)); // Make the run path the default plugin search location QCoreApplication::addLibraryPath(openstudio::toQString(openstudio::getApplicationRunDirectory())); openstudio::pat::PatApp app(argc, argv, infoGetter); openstudio::Application::instance().setApplication(&app); try { return app.exec(); } catch (const std::exception &e) { LOG_FREE(Fatal, "PatApp", "An unhandled exception has occurred: " << e.what()); cont = true; QMessageBox msgBox; msgBox.setWindowTitle("Unhandled Exception"); msgBox.setIcon(QMessageBox::Critical); msgBox.setText("An unhandled exception has occurred."); msgBox.setInformativeText(e.what()); msgBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Close); msgBox.button(QMessageBox::Retry)->setText("Relaunch"); if (msgBox.exec() == QMessageBox::Close) { cont = false; } } catch (...) { LOG_FREE(Fatal, "PatApp", "An unknown exception has occurred."); cont = true; QMessageBox msgBox; msgBox.setWindowTitle("Unknown Exception"); msgBox.setIcon(QMessageBox::Critical); msgBox.setText("An unknown exception has occurred."); msgBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Close); msgBox.button(QMessageBox::Retry)->setText("Relaunch"); if (msgBox.exec() == QMessageBox::Close) { cont = false; } } } }
int main(int argc, char *argv[]) { #if RUBY_API_VERSION_MAJOR && RUBY_API_VERSION_MAJOR==2 ruby_sysinit(&argc, &argv); { RUBY_INIT_STACK; ruby_init(); } #endif #if _DEBUG || (__GNUC__ && !NDEBUG) openstudio::Logger::instance().standardOutLogger().setLogLevel(Debug); openstudio::FileLogSink fileLog(openstudio::toPath(logfilepath)); fileLog.setLogLevel(Debug); #else openstudio::Logger::instance().standardOutLogger().setLogLevel(Warn); #endif bool cont = true; while(cont) { cont = false; std::vector<std::string> modules; modules.push_back("openstudioutilitiescore"); modules.push_back("openstudioutilitiesbcl"); modules.push_back("openstudioutilitiesidd"); modules.push_back("openstudioutilitiesidf"); modules.push_back("openstudioutilities"); modules.push_back("openstudiomodel"); modules.push_back("openstudiomodelcore"); modules.push_back("openstudiomodelsimulation"); modules.push_back("openstudiomodelresources"); modules.push_back("openstudiomodelgeometry"); modules.push_back("openstudiomodelhvac"); modules.push_back("openstudioenergyplus"); modules.push_back("openstudioruleset"); //try { // Initialize the embedded Ruby interpreter boost::shared_ptr<openstudio::detail::RubyInterpreter> rubyInterpreter( new openstudio::detail::RubyInterpreter(openstudio::getOpenStudioRubyPath(), openstudio::getOpenStudioRubyScriptsPath(), modules)); // Initialize the argument getter QSharedPointer<openstudio::ruleset::RubyUserScriptArgumentGetter> argumentGetter( new openstudio::ruleset::detail::RubyUserScriptArgumentGetter_Impl<openstudio::detail::RubyInterpreter>(rubyInterpreter)); openstudio::OpenStudioApp app(argc, argv, argumentGetter); openstudio::Application::instance().setApplication(&app); try { return app.exec(); } catch (const std::exception &e) { LOG_FREE(Fatal, "OpenStudio", "An unhandled exception has occurred: " << e.what()); cont = true; QMessageBox msgBox; msgBox.setWindowTitle("Unhandled Exception"); msgBox.setIcon(QMessageBox::Critical); msgBox.setText("An unhandled exception has occurred."); msgBox.setInformativeText(e.what()); msgBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Close); msgBox.button(QMessageBox::Retry)->setText("Relaunch"); if (msgBox.exec() == QMessageBox::Close) { cont = false; } } catch (...) { LOG_FREE(Fatal, "OpenStudio", "An unknown exception has occurred."); cont = true; QMessageBox msgBox; msgBox.setWindowTitle("Unknown Exception"); msgBox.setIcon(QMessageBox::Critical); msgBox.setText("An unknown exception has occurred."); msgBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Close); msgBox.button(QMessageBox::Retry)->setText("Relaunch"); if (msgBox.exec() == QMessageBox::Close) { cont = false; } } } }
static void ruby_coroutine_body( #ifdef DEMONSTRATE_PTHREAD void* dummy_argument_that_is_not_used #endif ) { #ifdef DEMONSTRATE_PTHREAD printf("Coroutine: waiting for initial asynchronous relay from main\n"); relay_from_ruby_to_main(Qnil); #endif printf("Coroutine: begin\n"); int i; for (i = 0; i < 2; i++) { printf("Coroutine: relay %d\n", i); relay_from_ruby_to_main(Qnil); } printf("Coroutine: Ruby begin\n"); #ifdef HAVE_RUBY_SYSINIT int argc = 0; char** argv = {""}; ruby_sysinit(&argc, &argv); #endif { #ifdef HAVE_RUBY_BIND_STACK ruby_bind_stack( /* lower memory address */ (VALUE*)(ruby_coroutine_stack), /* upper memory address */ (VALUE*)(ruby_coroutine_stack + ruby_coroutine_stack_size) ); #endif RUBY_INIT_STACK; 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); /* run the "hello world" Ruby script */ printf("Ruby: require 'hello' begin\n"); ruby_coroutine_body_require("./hello.rb"); printf("Ruby: require 'hello' end\n"); ruby_cleanup(0); } printf("Coroutine: Ruby end\n"); printf("Coroutine: end\n"); ruby_coroutine_finished = true; relay_from_ruby_to_main(Qnil); #ifdef DEMONSTRATE_PTHREAD pthread_exit(NULL); #endif }