From 2a012591923863963629e60b138e330cfdca6d27 Mon Sep 17 00:00:00 2001 From: lethosor Date: Tue, 10 Jun 2014 21:38:21 -0400 Subject: [PATCH] Fix runCommand crash, return output and result --- library/LuaApi.cpp | 9 +++------ library/lua/dfhack.lua | 9 ++++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index d64551bab..af318f305 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -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++) { diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua index b2f456532..970d50a4a 100644 --- a/library/lua/dfhack.lua +++ b/library/lua/dfhack.lua @@ -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