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);