diff --git a/library/Core.cpp b/library/Core.cpp index 9c2295435..2696e9526 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -661,32 +661,43 @@ command_result Core::runCommand(color_ostream &con, const std::string &first_, v for (size_t i = 0; i < parts.size(); i++) { - Plugin * plug = plug_mgr->getPluginByName(parts[i]); + std::string part = parts[i]; + if (part.find('\\') != std::string::npos) + { + con.printerr("Replacing backslashes with forward slashes in \"%s\"\n", part.c_str()); + for (size_t j = 0; j < part.size(); j++) + { + if (part[j] == '\\') + part[j] = '/'; + } + } + + Plugin * plug = plug_mgr->getPluginByName(part); if(!plug) { - std::string lua = findScript(this->p->getPath(), parts[i] + ".lua"); + std::string lua = findScript(this->p->getPath(), part + ".lua"); if (lua.size()) { - res = enableLuaScript(con, parts[i], enable); + res = enableLuaScript(con, part, enable); } else { res = CR_NOT_FOUND; - con.printerr("No such plugin or Lua script: %s\n", parts[i].c_str()); + con.printerr("No such plugin or Lua script: %s\n", part.c_str()); } } else if (!plug->can_set_enabled()) { res = CR_NOT_IMPLEMENTED; - con.printerr("Cannot %s plugin: %s\n", first.c_str(), parts[i].c_str()); + con.printerr("Cannot %s plugin: %s\n", first.c_str(), part.c_str()); } else { res = plug->set_enabled(con, enable); if (res != CR_OK || plug->is_enabled() != enable) - con.printerr("Could not %s plugin: %s\n", first.c_str(), parts[i].c_str()); + con.printerr("Could not %s plugin: %s\n", first.c_str(), part.c_str()); } } diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua index 4f2f3f580..bdf9a1227 100644 --- a/library/lua/dfhack.lua +++ b/library/lua/dfhack.lua @@ -399,9 +399,13 @@ function Script:get_flags() local f = io.open(self.path) local contents = f:read('*all') f:close() - for line in contents:gmatch('--@([^\n]+)') do + for line in contents:gmatch('%-%-@([^\n]+)') do local chunk = load(line, self.path, 't', self._flags) - if chunk then chunk() end + if chunk then + chunk() + else + dfhack.printerr('Parse error: ' .. line) + end end end return self._flags @@ -434,7 +438,7 @@ function dfhack.findScript(name) end local valid_script_flags = { - enable = {required = true}, + enable = {required = true, error = 'Does not recognize enable/disable commands'}, enable_state = {required = false}, module = {required = true, error = 'Cannot be used as a module'}, } @@ -444,9 +448,10 @@ function dfhack.run_script(name,...) end function dfhack.enable_script(name, state) - local res = dfhack.pcall(dfhack.run_script_with_env, nil, name, {enable=true, enable_state=state}) + local res, err = dfhack.pcall(dfhack.run_script_with_env, nil, name, {enable=true, enable_state=state}) if not res then - qerror('Cannot ' .. (state and 'enable' or 'disable') .. ' Lua script: ' .. name) + dfhack.printerr(err.message) + qerror(('Cannot %s Lua script: %s'):format(state and 'enable' or 'disable', name)) end end