move arg checking code to the top

This commit is contained in:
takase1121 2021-07-08 11:20:08 +08:00
parent 9e5b6c72a7
commit b38add8de5
1 changed files with 7 additions and 0 deletions

View File

@ -59,6 +59,13 @@ static int process_start(lua_State* L)
{ {
int cmd_len = lua_rawlen(L, 1) + 1; int cmd_len = lua_rawlen(L, 1) + 1;
const char** cmd = malloc(sizeof(char *) * cmd_len); const char** cmd = malloc(sizeof(char *) * cmd_len);
luaL_checktype(L, 1, LUA_TTABLE);
if (lua_isnoneornil(L, 2)) {
lua_settop(L, 1); // remove the nil if it's there
lua_newtable(L);
}
luaL_checktype(L, 2, LUA_TTABLE);
ASSERT_MALLOC(cmd); ASSERT_MALLOC(cmd);
cmd[cmd_len] = NULL; cmd[cmd_len] = NULL;