From c8e272d20b4befb7aae0a67d4c5698be061d5360 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Wed, 11 Jun 2014 13:18:35 -0700 Subject: [PATCH] feat(util/lua): add check_atleast_num_args helper function Signed-off-by: Leonardo de Moura --- src/util/lua.cpp | 8 +++++--- src/util/lua.h | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/util/lua.cpp b/src/util/lua.cpp index 80d920896..654dd3d2a 100644 --- a/src/util/lua.cpp +++ b/src/util/lua.cpp @@ -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"); } } diff --git a/src/util/lua.h b/src/util/lua.h index 7eb60ed15..d4d08d72a 100644 --- a/src/util/lua.h +++ b/src/util/lua.h @@ -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); // ======================================= }