Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept nil for params and options arguments for Spring.GiveOrder family functions. #1822

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions rts/Lua/LuaSyncedCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5209,8 +5209,8 @@ int LuaSyncedCtrl::SetProjectileCEG(lua_State* L)
* Used when assigning multiple commands at once
*
* @number cmdID
* @tparam {number,...} params
* @tparam cmdOpts options
* @tparam {number,...}|nil params
* @tparam cmdOpts|nil options
*/


Expand Down Expand Up @@ -5239,8 +5239,8 @@ int LuaSyncedCtrl::UnitFinishCommand(lua_State* L)
* @function Spring.GiveOrderToUnit
* @number unitID
* @number cmdID
* @tparam {number,...} params
* @tparam cmdOpts options
* @tparam {number,...}|nil params
* @tparam cmdOpts|nil options
* @treturn bool unitOrdered
*/
int LuaSyncedCtrl::GiveOrderToUnit(lua_State* L)
Expand Down Expand Up @@ -5275,8 +5275,8 @@ int LuaSyncedCtrl::GiveOrderToUnit(lua_State* L)
* @function Spring.GiveOrderToUnitMap
* @tparam {[number]=table,...} unitMap table with unitIDs as keys
* @number cmdID
* @tparam {number,...} params
* @tparam cmdOpts options
* @tparam {number,...}|nil params
* @tparam cmdOpts|nil options
* @treturn number unitsOrdered
*/
int LuaSyncedCtrl::GiveOrderToUnitMap(lua_State* L)
Expand Down Expand Up @@ -5318,8 +5318,8 @@ int LuaSyncedCtrl::GiveOrderToUnitMap(lua_State* L)
* @function Spring.GiveOrderToUnitArray
* @tparam {number,...} unitIDs
* @number cmdID
* @tparam {number,...} params
* @tparam cmdOpts options
* @tparam {number,...}|nil params
* @tparam cmdOpts|nil options
* @treturn number unitsOrdered
*/
int LuaSyncedCtrl::GiveOrderToUnitArray(lua_State* L)
Expand Down
12 changes: 8 additions & 4 deletions rts/Lua/LuaUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,10 @@ static bool ParseCommandOptions(
return true;
}

if (lua_isnoneornil(L, idx)) {
return true;
sprunk marked this conversation as resolved.
Show resolved Hide resolved
}

if (lua_istable(L, idx)) {
for (lua_pushnil(L); lua_next(L, idx) != 0; lua_pop(L, 1)) {
// "key" = value (table format of CommandNotify)
Expand Down Expand Up @@ -1080,8 +1084,8 @@ Command LuaUtils::ParseCommand(lua_State* L, const char* caller, int idIndex)

cmd.PushParam(lua_tofloat(L, -1));
}
} else {
luaL_error(L, "%s(): bad param (expected table or number)", caller);
} else if (!lua_isnoneornil(L, paramTableIdx)) {
luaL_error(L, "%s(): bad param (expected table, number or nil)", caller);
}
}

Expand Down Expand Up @@ -1124,8 +1128,8 @@ Command LuaUtils::ParseCommandTable(lua_State* L, const char* caller, int tableI

cmd.PushParam(lua_tofloat(L, -1));
}
} else {
luaL_error(L, "%s(): bad param (expected table or number)", caller);
} else if (!lua_isnil(L, -1)) {
luaL_error(L, "%s(): bad param (expected table, number or nil)", caller);
}

lua_pop(L, 1);
Expand Down