feat(util/lua): add check_atleast_num_args helper function

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-06-11 13:18:35 -07:00
parent 1972a09021
commit c8e272d20b
2 changed files with 7 additions and 3 deletions

View file

@ -197,11 +197,13 @@ lua_migrate_fn get_migrate_fn(lua_State * L, int i) {
}
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) {
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");
}
}

View file

@ -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);
/** \brief Throw an exception if lua_gettop(L) > 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);
// =======================================
}