|
|
@ -2822,13 +2822,25 @@ static int internal_diffscan(lua_State *L)
|
|
|
|
|
|
|
|
|
|
|
|
static int internal_runCommand(lua_State *L)
|
|
|
|
static int internal_runCommand(lua_State *L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
buffered_color_ostream out;
|
|
|
|
color_ostream *out = NULL;
|
|
|
|
|
|
|
|
std::unique_ptr<buffered_color_ostream> out_buffer;
|
|
|
|
command_result res;
|
|
|
|
command_result res;
|
|
|
|
if (lua_gettop(L) == 0)
|
|
|
|
if (lua_gettop(L) == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_pushstring(L, "");
|
|
|
|
lua_pushstring(L, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int type_1 = lua_type(L, 1);
|
|
|
|
int type_1 = lua_type(L, 1);
|
|
|
|
|
|
|
|
bool use_console = lua_toboolean(L, 2);
|
|
|
|
|
|
|
|
if (use_console)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
out = &Core::getInstance().getConsole();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
out_buffer.reset(new buffered_color_ostream());
|
|
|
|
|
|
|
|
out = out_buffer.get();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (type_1 == LUA_TTABLE)
|
|
|
|
if (type_1 == LUA_TTABLE)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string command = "";
|
|
|
|
std::string command = "";
|
|
|
@ -2843,13 +2855,13 @@ static int internal_runCommand(lua_State *L)
|
|
|
|
lua_pop(L, 1); // remove value, leave key
|
|
|
|
lua_pop(L, 1); // remove value, leave key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CoreSuspender suspend;
|
|
|
|
CoreSuspender suspend;
|
|
|
|
res = Core::getInstance().runCommand(out, command, args);
|
|
|
|
res = Core::getInstance().runCommand(*out, command, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type_1 == LUA_TSTRING)
|
|
|
|
else if (type_1 == LUA_TSTRING)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string command = lua_tostring(L, 1);
|
|
|
|
std::string command = lua_tostring(L, 1);
|
|
|
|
CoreSuspender suspend;
|
|
|
|
CoreSuspender suspend;
|
|
|
|
res = Core::getInstance().runCommand(out, command);
|
|
|
|
res = Core::getInstance().runCommand(*out, command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -2857,22 +2869,28 @@ static int internal_runCommand(lua_State *L)
|
|
|
|
lua_pushfstring(L, "Expected table, got %s", lua_typename(L, type_1));
|
|
|
|
lua_pushfstring(L, "Expected table, got %s", lua_typename(L, type_1));
|
|
|
|
return 2;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto fragments = out.fragments();
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_pushinteger(L, (int)res);
|
|
|
|
lua_pushinteger(L, (int)res);
|
|
|
|
lua_setfield(L, -2, "status");
|
|
|
|
lua_setfield(L, -2, "status");
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
for (auto iter = fragments.begin(); iter != fragments.end(); iter++, i++)
|
|
|
|
if (out_buffer)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int color = iter->first;
|
|
|
|
auto fragments = out_buffer->fragments();
|
|
|
|
std::string output = iter->second;
|
|
|
|
int i = 1;
|
|
|
|
lua_createtable(L, 2, 0);
|
|
|
|
for (auto iter = fragments.begin(); iter != fragments.end(); iter++, i++)
|
|
|
|
lua_pushinteger(L, color);
|
|
|
|
{
|
|
|
|
lua_rawseti(L, -2, 1);
|
|
|
|
int color = iter->first;
|
|
|
|
lua_pushstring(L, output.c_str());
|
|
|
|
std::string output = iter->second;
|
|
|
|
lua_rawseti(L, -2, 2);
|
|
|
|
lua_createtable(L, 2, 0);
|
|
|
|
lua_rawseti(L, -2, i);
|
|
|
|
lua_pushinteger(L, color);
|
|
|
|
|
|
|
|
lua_rawseti(L, -2, 1);
|
|
|
|
|
|
|
|
lua_pushstring(L, output.c_str());
|
|
|
|
|
|
|
|
lua_rawseti(L, -2, 2);
|
|
|
|
|
|
|
|
lua_rawseti(L, -2, i);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lua_pushvalue(L, -1);
|
|
|
|
lua_pushvalue(L, -1);
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|