Skip to content

Commit

Permalink
fix #6128
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed Feb 5, 2019
1 parent c3263ce commit be99910
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions rts/Lua/LuaUtils.cpp
Expand Up @@ -930,22 +930,22 @@ void LuaUtils::PushUnitAndCommand(lua_State* L, const CUnit* unit, const Command
}


static void ParseCommandOptions(
static bool ParseCommandOptions(
lua_State* L,
Command& cmd,
const char* caller,
const int idx
) {
if (lua_isnumber(L, idx)) {
cmd.SetOpts(lua_tonumber(L, idx));
return;
return true;
}

if (lua_istable(L, idx)) {
for (lua_pushnil(L); lua_next(L, idx) != 0; lua_pop(L, 1)) {
// "key" = value (table format of CommandNotify)
// ignore the "coded" key; not a boolean value
if (lua_israwstring(L, -2)) {
// we do not care about the "coded" key (not a boolean value)
if (!lua_isboolean(L, -1))
continue;

Expand Down Expand Up @@ -974,8 +974,6 @@ static void ParseCommandOptions(

// [idx] = "value", avoid 'n'
if (lua_israwnumber(L, -2)) {
//const int idx = lua_tonumber(L, -2);

if (!lua_isstring(L, -1))
continue;

Expand All @@ -999,12 +997,25 @@ static void ParseCommandOptions(
}
}

return;
return true;
}

luaL_error(L, "%s(): bad options-argument type", caller);
return false;
}

static bool ParseCommandTimeOut(
lua_State* L,
Command& cmd,
const char* caller,
const int idx
) {
if (!lua_isnumber(L, idx))
return false;

cmd.SetTimeOut(lua_tonumber(L, idx));
return true;
}

Command LuaUtils::ParseCommand(lua_State* L, const char* caller, int idIndex)
{
Expand Down Expand Up @@ -1037,6 +1048,8 @@ Command LuaUtils::ParseCommand(lua_State* L, const char* caller, int idIndex)

// options
ParseCommandOptions(L, cmd, caller, idIndex + 2);
// timeout
ParseCommandTimeOut(L, cmd, caller, idIndex + 3);

// XXX should do some sanity checking?
return cmd;
Expand Down Expand Up @@ -1085,6 +1098,12 @@ Command LuaUtils::ParseCommandTable(lua_State* L, const char* caller, int tableI
ParseCommandOptions(L, cmd, caller, lua_gettop(L));
lua_pop(L, 1);
}
{
// timeout
lua_rawgeti(L, tableIdx, 4);
ParseCommandTimeOut(L, cmd, caller, lua_gettop(L));
lua_pop(L, 1);
}

// XXX should do some sanity checking?
return cmd;
Expand Down

0 comments on commit be99910

Please sign in to comment.