diff --git a/library/Core.cpp b/library/Core.cpp index b8a5f4808..2459559dd 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -259,7 +259,7 @@ static void listScripts(PluginManager *plug_mgr, std::map &pset, pset[prefix + files[i].substr(0, files[i].size()-4)] = help; } - else if (plug_mgr->eval_ruby && hasEnding(files[i], ".rb")) + else if (plug_mgr->ruby && plug_mgr->ruby->is_enabled() && hasEnding(files[i], ".rb")) { std::string help = getScriptHelp(path + files[i], "# "); @@ -312,6 +312,9 @@ static command_result runLuaScript(color_ostream &out, std::string name, vector< static command_result runRubyScript(color_ostream &out, PluginManager *plug_mgr, std::string name, vector &args) { + if (!plug_mgr->ruby || !plug_mgr->ruby->is_enabled()) + return CR_FAILURE; + std::string rbcmd = "$script_args = ["; for (size_t i = 0; i < args.size(); i++) rbcmd += "'" + args[i] + "', "; @@ -319,7 +322,7 @@ static command_result runRubyScript(color_ostream &out, PluginManager *plug_mgr, rbcmd += "catch(:script_finished) { load './hack/scripts/" + name + ".rb' }"; - return plug_mgr->eval_ruby(out, rbcmd.c_str()); + return plug_mgr->ruby->eval_ruby(out, rbcmd.c_str()); } command_result Core::runCommand(color_ostream &out, const std::string &command) @@ -450,7 +453,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first, ve con.print("%s: %s\n", parts[0].c_str(), help.c_str()); return CR_OK; } - if (plug_mgr->eval_ruby && fileExists(filename + ".rb")) + if (plug_mgr->ruby && plug_mgr->ruby->is_enabled() && fileExists(filename + ".rb")) { string help = getScriptHelp(filename + ".rb", "# "); con.print("%s: %s\n", parts[0].c_str(), help.c_str()); @@ -767,7 +770,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first, ve if (fileExists(filename + ".lua")) res = runLuaScript(con, first, parts); - else if (plug_mgr->eval_ruby && fileExists(filename + ".rb")) + else if (plug_mgr->ruby && plug_mgr->ruby->is_enabled() && fileExists(filename + ".rb")) res = runRubyScript(con, plug_mgr, first, parts); else if (try_autocomplete(con, first, completed)) return CR_NOT_IMPLEMENTED;// runCommand(con, completed, parts); diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp index 3ef4910cb..28d57c76f 100644 --- a/library/PluginManager.cpp +++ b/library/PluginManager.cpp @@ -679,7 +679,7 @@ void Plugin::push_function(lua_State *state, LuaFunction *fn) PluginManager::PluginManager(Core * core) { cmdlist_mutex = new mutex(); - eval_ruby = NULL; + ruby = NULL; } PluginManager::~PluginManager() @@ -774,7 +774,7 @@ void PluginManager::registerCommands( Plugin * p ) belongs[cmds[i].name] = p; } if (p->plugin_eval_ruby) - eval_ruby = p->plugin_eval_ruby; + ruby = p; cmdlist_mutex->unlock(); } @@ -788,6 +788,6 @@ void PluginManager::unregisterCommands( Plugin * p ) belongs.erase(cmds[i].name); } if (p->plugin_eval_ruby) - eval_ruby = NULL; + ruby = NULL; cmdlist_mutex->unlock(); } diff --git a/library/include/PluginManager.h b/library/include/PluginManager.h index 506ca33c0..b47863d48 100644 --- a/library/include/PluginManager.h +++ b/library/include/PluginManager.h @@ -170,6 +170,12 @@ namespace DFHack void open_lua(lua_State *state, int table); + command_result eval_ruby(color_ostream &out, const char* cmd) { + if (!plugin_eval_ruby || !is_enabled()) + return CR_FAILURE; + return plugin_eval_ruby(out, cmd); + } + private: RefLock * access; std::vector commands; @@ -236,7 +242,7 @@ namespace DFHack { return all_plugins.size(); } - command_result (*eval_ruby)(color_ostream &, const char*); + Plugin *ruby; // DATA private: tthread::mutex * cmdlist_mutex;