Fix runCommand crash, return output and result

develop
lethosor 2014-06-10 21:38:21 -04:00
parent 143b1e3469
commit 2a01259192
2 changed files with 7 additions and 11 deletions

@ -2230,18 +2230,15 @@ static int internal_getDir(lua_State *L)
static int internal_runCommand(lua_State *L)
{
CoreSuspender suspend;
luaL_checktype(L, 1, LUA_TSTRING);
CoreSuspender suspend;
std::string command = lua_tostring(L, 1);
buffered_color_ostream out;
command_result res = Core::getInstance().runCommand(out, command);
if (res != CR_OK)
{
lua_pushinteger(L, (int)res);
return 1;
}
auto fragments = out.fragments();
lua_newtable(L);
lua_pushinteger(L, (int)res);
lua_setfield(L, -2, "status");
int i = 1;
for (auto iter = fragments.begin(); iter != fragments.end(); iter++, i++)
{

@ -374,14 +374,13 @@ function dfhack.run_command(...)
command = table.concat(args, ' ')
end
result = internal.runCommand(command)
if type(result) == 'number' then
return result
end
output = ""
for i, f in pairs(result) do
output = output .. f[2]
if type(f) == 'table' then
output = output .. f[2]
end
end
return output
return output, result.status
end
-- Per-save init file