From: Aki Tuomi Date: Thu, 18 Oct 2018 09:04:41 +0000 (+0300) Subject: lib-lua: Add DLUA_REQUIRE_ARGS(s,x) and DLUA_REQUIRE_ARGS_IN(s,x,y) X-Git-Tag: 2.3.9~1180 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2ba3ed50ecf5bb78a9846bd3cc4b2a32cac3f0ca;p=thirdparty%2Fdovecot%2Fcore.git lib-lua: Add DLUA_REQUIRE_ARGS(s,x) and DLUA_REQUIRE_ARGS_IN(s,x,y) First form requires that x arguments are provided for dlua script s. Second form requires that at least x and at most y arguments are provided for dlua script s Automatically returns luaL_error. --- diff --git a/src/lib-lua/dlua-script-private.h b/src/lib-lua/dlua-script-private.h index ddd7ac8a4a..caa0f63621 100644 --- a/src/lib-lua/dlua-script-private.h +++ b/src/lib-lua/dlua-script-private.h @@ -35,6 +35,9 @@ void luaL_setmetatable (lua_State *L, const char *tname); #define DLUA_TABLE_NULL(n, s) { .name = n, .type = DLUA_TABLE_VALUE_NULL } #define DLUA_TABLE_END { .name = NULL } +#define DLUA_REQUIRE_ARGS_IN(s,x,y) if (lua_gettop((s)->L) < (x) || lua_gettop((s)->L) > (y)) { return luaL_error((s)->L, "expected %d to %d arguments, got %d", x, y, lua_gettop((s)->L)); } +#define DLUA_REQUIRE_ARGS(s,x) if (lua_gettop((s)->L) != (x)) { return luaL_error((s)->L, "expected %d arguments, got %d", (x), lua_gettop((s)->L)); } + struct dlua_script { struct dlua_script *prev,*next; pool_t pool;