]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lua: clarify event.recurrent() API
authorPetr Špaček <petr.spacek@nic.cz>
Tue, 18 Aug 2020 07:42:56 +0000 (09:42 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 25 Aug 2020 07:17:04 +0000 (09:17 +0200)
It was rather confusing:
- event.after(0, ...) executed function immediatelly
- event.recurrent(0, ...) executed function immediatelly (seemingly worked)
  but stoped after the first execution, i.e. no recurrence took place.

daemon/bindings/event.c
daemon/bindings/event.rst

index e53f228e99f40db0a9bce83d7ae4f23f6a25098b..0c5a6ba97b8f53c01e18ab5993e19977b95049e6 100644 (file)
@@ -94,7 +94,8 @@ static int event_recurrent(lua_State *L)
 {
        /* Check parameters */
        int n = lua_gettop(L);
-       if (n < 2 || !lua_isnumber(L, 1) || !lua_isfunction(L, 2))
+       if (n < 2 || !lua_isnumber(L, 1)  || lua_tointeger(L, 1) == 0
+               || !lua_isfunction(L, 2))
                lua_error_p(L, "expected 'recurrent(number interval, function)'");
 
        return event_sched(L, 0, lua_tointeger(L, 1));
index 6150f2309e5dc565be942d4ce91728568403cc68..bb8abcdd775ed13f9023e4af22cc8f571ee3f60a 100644 (file)
@@ -25,7 +25,7 @@ For example, ``5 * hour`` represents five hours, or 5*60*60*100 milliseconds.
 
    :return: event id
 
-   Similar to :func:`event.after()`, periodically execute function after ``interval`` passes.
+   Execute function immediatelly and then periodically after each ``interval``.
 
    Example: