]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-lua: Add DLUA_REQUIRE_ARGS(s,x) and DLUA_REQUIRE_ARGS_IN(s,x,y)
authorAki Tuomi <aki.tuomi@dovecot.fi>
Thu, 18 Oct 2018 09:04:41 +0000 (12:04 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Wed, 14 Nov 2018 12:12:02 +0000 (14:12 +0200)
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.

src/lib-lua/dlua-script-private.h

index 1b5cb01735f514963a51ac729088cf38dd6a8c88..7f521b5904fa035a68195ff6efa4ad70c4c0a013 100644 (file)
@@ -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;