diff --git a/src/pyastub/pya.cc b/src/pyastub/pya.cc index 7ec5bdbb4..c343b094d 100644 --- a/src/pyastub/pya.cc +++ b/src/pyastub/pya.cc @@ -31,14 +31,23 @@ static void fail (const char *file, int line) throw tl::ScriptError (tl::to_string (QObject::tr ("Python support not compiled in")).c_str (), file, line, "missing_feature", std::vector ()); } -PythonInterpreter::PythonInterpreter () -{ - // .. nothing .. +static PythonInterpreter *sp_pya_interpreter = 0; + +PythonInterpreter::PythonInterpreter () +{ + tl_assert (! sp_pya_interpreter); + sp_pya_interpreter = this; } -PythonInterpreter::~PythonInterpreter () +PythonInterpreter::~PythonInterpreter () { - // .. nothing .. + // This prevents reinitialization + sp_pya_interpreter = reinterpret_cast (1); +} + +PythonInterpreter *PythonInterpreter::instance () +{ + return sp_pya_interpreter; } void @@ -162,11 +171,5 @@ PythonInterpreter::eval_expr (const char *, const char *file, int line, int) return tl::Variant (); } -PythonInterpreter * -PythonInterpreter::instance () -{ - return 0; -} - } diff --git a/src/pyastub/pya.h b/src/pyastub/pya.h index 6e0c2e144..da5a48b92 100644 --- a/src/pyastub/pya.h +++ b/src/pyastub/pya.h @@ -168,10 +168,9 @@ public: static void initialize (); /** - * @brief Always returns 0 + * @brief Returns the singleton reference */ static PythonInterpreter *instance (); - }; } diff --git a/src/pyastub/pyastub.pro b/src/pyastub/pyastub.pro index 5aa72a343..78e2be02d 100644 --- a/src/pyastub/pyastub.pro +++ b/src/pyastub/pyastub.pro @@ -13,5 +13,6 @@ DEPENDPATH += $$TL_INC $$GSI_INC LIBS += -L$$DESTDIR -lklayout_tl -lklayout_gsi HEADERS += \ - pyaCommon.h + pyaCommon.h \ + pya.h diff --git a/src/rbastub/rba.cc b/src/rbastub/rba.cc index 02398bfb0..48619942b 100644 --- a/src/rbastub/rba.cc +++ b/src/rbastub/rba.cc @@ -30,14 +30,23 @@ static void fail (const char *file, int line) throw tl::ScriptError (tl::to_string (QObject::tr ("Ruby support not compiled in")).c_str (), file, line, "missing_feature", std::vector ()); } -RubyInterpreter::RubyInterpreter () -{ - // .. nothing .. +static RubyInterpreter *sp_rba_interpreter = 0; + +RubyInterpreter::RubyInterpreter () +{ + tl_assert (! sp_rba_interpreter); + sp_rba_interpreter = this; } -RubyInterpreter::~RubyInterpreter () +RubyInterpreter::~RubyInterpreter () { - // .. nothing .. + // This prevents reinitialization + sp_rba_interpreter = reinterpret_cast (1); +} + +RubyInterpreter *RubyInterpreter::instance () +{ + return sp_rba_interpreter; } void diff --git a/src/rbastub/rba.h b/src/rbastub/rba.h index 1644df201..3985b4d6b 100644 --- a/src/rbastub/rba.h +++ b/src/rbastub/rba.h @@ -150,6 +150,11 @@ public: */ std::string version () const; + /** + * @brief The instance of the Ruby interpreter + */ + static RubyInterpreter *instance (); + /** * @brief Provide a first (basic) initialization and continue with the "main_cont" function internally */ diff --git a/src/rbastub/rbastub.pro b/src/rbastub/rbastub.pro index 328245d8d..25b34917f 100644 --- a/src/rbastub/rbastub.pro +++ b/src/rbastub/rbastub.pro @@ -6,7 +6,7 @@ include($$PWD/../lib.pri) DEFINES += MAKE_RBA_LIBRARY -HEADERS = rbaCommon.h +HEADERS = rbaCommon.h rba.h SOURCES = rba.cc