From fb922fab37128ab41af77995379a6e08705465e1 Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 16 Jun 2014 11:40:26 -0400 Subject: [PATCH] Handle invalid arguments to runCommand --- library/LuaApi.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 11cefcc06..529f51edb 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -2236,7 +2236,8 @@ static int internal_runCommand(lua_State *L) { lua_pushstring(L, ""); } - if (lua_type(L, 1) == LUA_TTABLE) + int type_1 = lua_type(L, 1); + if (type_1 == LUA_TTABLE) { std::string command = ""; std::vector args; @@ -2252,12 +2253,18 @@ static int internal_runCommand(lua_State *L) CoreSuspender suspend; res = Core::getInstance().runCommand(out, command, args); } - else + else if (type_1 == LUA_TSTRING) { std::string command = lua_tostring(L, 1); CoreSuspender suspend; res = Core::getInstance().runCommand(out, command); } + else + { + lua_pushnil(L); + lua_pushfstring(L, "Expected table, got %s", lua_typename(L, type_1)); + return 2; + } auto fragments = out.fragments(); lua_newtable(L); lua_pushinteger(L, (int)res);