ruby/engine/InitRubyEngine.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #include "./RubyEngine.hpp" | ||
| 7 | #include "./InitRubyEngine.hpp" | ||
| 8 | #include "./GC_Value.hpp" | ||
| 9 | #include <RubyInterpreter.hpp> | ||
| 10 | #include <iostream> | ||
| 11 | #include <embedded_files.hxx> | ||
| 12 | |||
| 13 | extern "C" | ||
| 14 | { | ||
| 15 | // static void Init_builtin_prelude(void); | ||
| 16 | // void Init_builtin_gem_prelude(void); | ||
| 17 | struct ruby_cmdline_options; | ||
| 18 | typedef struct ruby_cmdline_options ruby_cmdline_options_t; | ||
| 19 | void Init_ruby_description(ruby_cmdline_options_t*); | ||
| 20 | } | ||
| 21 | |||
| 22 | namespace openstudio { | ||
| 23 | |||
| 24 | 245 | void RubyEngine::initRubyEngine() { | |
| 25 |
1/1✓ Branch 1 taken 245 times.
|
245 | RUBY_INIT_STACK; |
| 26 |
1/1✓ Branch 1 taken 245 times.
|
245 | ruby_init(); |
| 27 | |||
| 28 |
1/1✓ Branch 1 taken 245 times.
|
245 | Init_ruby_description(nullptr); |
| 29 | |||
| 30 |
1/1✓ Branch 1 taken 245 times.
|
245 | ruby_gc_set_params(); |
| 31 |
1/1✓ Branch 1 taken 245 times.
|
245 | ruby_init_loadpath(); |
| 32 | |||
| 33 |
1/1✓ Branch 1 taken 245 times.
|
245 | Init_enc(); |
| 34 | // rb_enc_set_default_internal(rb_enc_from_encoding(rb_utf8_encoding())); | ||
| 35 | // rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding())); | ||
| 36 | |||
| 37 |
1/1✓ Branch 1 taken 245 times.
|
245 | Init_ext(); /* load statically linked extensions before rubygems */ |
| 38 | // Init_extra_exts(); | ||
| 39 |
1/1✓ Branch 1 taken 245 times.
|
245 | rb_call_builtin_inits(); |
| 40 | |||
| 41 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::hash_id = rb_intern("hash"); |
| 42 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::lt_id = rb_intern("<"); |
| 43 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::gt_id = rb_intern(">"); |
| 44 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::eq_id = rb_intern("=="); |
| 45 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::le_id = rb_intern("<="); |
| 46 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::ge_id = rb_intern(">="); |
| 47 | |||
| 48 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::pos_id = rb_intern("+@"); |
| 49 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::neg_id = rb_intern("-@"); |
| 50 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::inv_id = rb_intern("~"); |
| 51 | |||
| 52 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::add_id = rb_intern("+"); |
| 53 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::sub_id = rb_intern("-"); |
| 54 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::mul_id = rb_intern("*"); |
| 55 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::div_id = rb_intern("/"); |
| 56 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::mod_id = rb_intern("%"); |
| 57 | |||
| 58 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::and_id = rb_intern("&"); |
| 59 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::or_id = rb_intern("|"); |
| 60 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::xor_id = rb_intern("^"); |
| 61 | |||
| 62 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::lshift_id = rb_intern("<<"); |
| 63 |
1/1✓ Branch 1 taken 245 times.
|
245 | swig::GC_VALUE::rshift_id = rb_intern(">>"); |
| 64 | |||
| 65 | // rb_provide("rbconfig.so"); | ||
| 66 | |||
| 67 | // Need embedded_help for requiring files out of the embedded system | ||
| 68 |
2/2✓ Branch 1 taken 245 times.
✓ Branch 4 taken 245 times.
|
245 | auto embedded_extensions_string = embedded_files::getFileAsString(":/embedded_help.rb"); |
| 69 | |||
| 70 | try { | ||
| 71 |
1/1✓ Branch 1 taken 245 times.
|
245 | rubyInterpreter.evalString(embedded_extensions_string); |
| 72 | ✗ | } catch (const std::exception& e) { | |
| 73 | ✗ | rubyInterpreter.evalString(R"(STDOUT.flush)"); | |
| 74 | ✗ | std::cout << "Exception in embedded_help: " << e.what() << std::endl; // endl will flush | |
| 75 | ✗ | ruby_cleanup(1); | |
| 76 | ✗ | throw; | |
| 77 | ✗ | } catch (...) { | |
| 78 | ✗ | rubyInterpreter.evalString(R"(STDOUT.flush)"); | |
| 79 | ✗ | std::cout << "Unknown Exception in embedded_help" << std::endl; // endl will flush | |
| 80 | ✗ | ruby_cleanup(1); | |
| 81 | ✗ | throw; | |
| 82 | ✗ | } | |
| 83 | 245 | } | |
| 84 | |||
| 85 | } // namespace openstudio | ||
| 86 |