ruby: dont list ruby scripts when ruby plugin is disabled

develop
jj 2013-10-07 14:17:38 +02:00
parent 4ba4f90147
commit 84033bd586
3 changed files with 17 additions and 8 deletions

@ -259,7 +259,7 @@ static void listScripts(PluginManager *plug_mgr, std::map<string,string> &pset,
pset[prefix + files[i].substr(0, files[i].size()-4)] = help; 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], "# "); 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<string> &args) static command_result runRubyScript(color_ostream &out, PluginManager *plug_mgr, std::string name, vector<string> &args)
{ {
if (!plug_mgr->ruby || !plug_mgr->ruby->is_enabled())
return CR_FAILURE;
std::string rbcmd = "$script_args = ["; std::string rbcmd = "$script_args = [";
for (size_t i = 0; i < args.size(); i++) for (size_t i = 0; i < args.size(); i++)
rbcmd += "'" + args[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' }"; 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) 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()); con.print("%s: %s\n", parts[0].c_str(), help.c_str());
return CR_OK; 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", "# "); string help = getScriptHelp(filename + ".rb", "# ");
con.print("%s: %s\n", parts[0].c_str(), help.c_str()); 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")) if (fileExists(filename + ".lua"))
res = runLuaScript(con, first, parts); 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); res = runRubyScript(con, plug_mgr, first, parts);
else if (try_autocomplete(con, first, completed)) else if (try_autocomplete(con, first, completed))
return CR_NOT_IMPLEMENTED;// runCommand(con, completed, parts); return CR_NOT_IMPLEMENTED;// runCommand(con, completed, parts);

@ -679,7 +679,7 @@ void Plugin::push_function(lua_State *state, LuaFunction *fn)
PluginManager::PluginManager(Core * core) PluginManager::PluginManager(Core * core)
{ {
cmdlist_mutex = new mutex(); cmdlist_mutex = new mutex();
eval_ruby = NULL; ruby = NULL;
} }
PluginManager::~PluginManager() PluginManager::~PluginManager()
@ -774,7 +774,7 @@ void PluginManager::registerCommands( Plugin * p )
belongs[cmds[i].name] = p; belongs[cmds[i].name] = p;
} }
if (p->plugin_eval_ruby) if (p->plugin_eval_ruby)
eval_ruby = p->plugin_eval_ruby; ruby = p;
cmdlist_mutex->unlock(); cmdlist_mutex->unlock();
} }
@ -788,6 +788,6 @@ void PluginManager::unregisterCommands( Plugin * p )
belongs.erase(cmds[i].name); belongs.erase(cmds[i].name);
} }
if (p->plugin_eval_ruby) if (p->plugin_eval_ruby)
eval_ruby = NULL; ruby = NULL;
cmdlist_mutex->unlock(); cmdlist_mutex->unlock();
} }

@ -170,6 +170,12 @@ namespace DFHack
void open_lua(lua_State *state, int table); 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: private:
RefLock * access; RefLock * access;
std::vector <PluginCommand> commands; std::vector <PluginCommand> commands;
@ -236,7 +242,7 @@ namespace DFHack
{ {
return all_plugins.size(); return all_plugins.size();
} }
command_result (*eval_ruby)(color_ostream &, const char*); Plugin *ruby;
// DATA // DATA
private: private:
tthread::mutex * cmdlist_mutex; tthread::mutex * cmdlist_mutex;