feat(util/lua): add check_atleast_num_args helper function
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
1972a09021
commit
c8e272d20b
2 changed files with 7 additions and 3 deletions
|
@ -197,11 +197,13 @@ lua_migrate_fn get_migrate_fn(lua_State * L, int i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_num_args(lua_State * L, int num) {
|
void check_num_args(lua_State * L, int num) {
|
||||||
if (lua_gettop(L) != num) throw exception("incorrect number of arguments in function application");
|
if (lua_gettop(L) != num) throw exception("incorrect number of arguments to function");
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_atmost_num_args(lua_State * L, int high) {
|
void check_atmost_num_args(lua_State * L, int high) {
|
||||||
if (lua_gettop(L) > high) throw exception("too many arguments in function application");
|
if (lua_gettop(L) > high) throw exception("too many arguments to function");
|
||||||
|
}
|
||||||
|
void check_atleast_num_args(lua_State * L, int low) {
|
||||||
|
if (lua_gettop(L) < low) throw exception("too few arguments to function");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,5 +143,7 @@ inline int push_nil(lua_State * L) { lua_pushnil(L); return 1; }
|
||||||
void check_num_args(lua_State * L, int num);
|
void check_num_args(lua_State * L, int num);
|
||||||
/** \brief Throw an exception if lua_gettop(L) > high */
|
/** \brief Throw an exception if lua_gettop(L) > high */
|
||||||
void check_atmost_num_args(lua_State * L, int high);
|
void check_atmost_num_args(lua_State * L, int high);
|
||||||
|
/** \brief Throw an exception if lua_gettop(L) < low */
|
||||||
|
void check_atleast_num_args(lua_State * L, int low);
|
||||||
// =======================================
|
// =======================================
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue