Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2848fbc3cf
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 98 lines (82 sloc) 1.9 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
/**
* Create a table for ev.Idle that gives access to the constructor for
* idle objects.
*
* [-0, +1, ?]
*/
static int luaopen_ev_idle(lua_State *L) {
    lua_pop(L, create_idle_mt(L));

    lua_createtable(L, 0, 1);

    lua_pushcfunction(L, idle_new);
    lua_setfield(L, -2, "new");

    return 1;
}

/**
* Create the idle metatable in the registry.
*
* [-0, +1, ?]
*/
static int create_idle_mt(lua_State *L) {

    static luaL_reg fns[] = {
        { "stop", idle_stop },
        { "start", idle_start },
        { NULL, NULL }
    };
    luaL_newmetatable(L, IDLE_MT);
    add_watcher_mt(L);
    luaL_register(L, NULL, fns);

    return 1;
}

/**
* Create a new idle object. Arguments:
* 1 - callback function.
*
* @see watcher_new()
*
* [+1, -0, ?]
*/
static int idle_new(lua_State* L) {
    ev_idle* idle;

    idle = watcher_new(L, sizeof(ev_idle), IDLE_MT);
    ev_idle_init(idle, &idle_cb);
    return 1;
}

/**
* @see watcher_cb()
*
* [+0, -0, m]
*/
static void idle_cb(struct ev_loop* loop, ev_idle* idle, int revents) {
    watcher_cb(loop, idle, revents);
}

/**
* Stops the idle so it won't be called by the specified event loop.
*
* Usage:
* idle:stop(loop)
*
* [+0, -0, e]
*/
static int idle_stop(lua_State *L) {
    ev_idle* idle = check_idle(L, 1);
    struct ev_loop* loop = *check_loop_and_init(L, 2);

    loop_stop_watcher(L, 2, 1);
    ev_idle_stop(loop, idle);

    return 0;
}

/**
* Starts the idle so it won't be called by the specified event loop.
*
* Usage:
* idle:start(loop [, is_daemon])
*
* [+0, -0, e]
*/
static int idle_start(lua_State *L) {
    ev_idle* idle = check_idle(L, 1);
    struct ev_loop* loop = *check_loop_and_init(L, 2);
    int is_daemon = lua_toboolean(L, 3);

    ev_idle_start(loop, idle);
    loop_start_watcher(L, 2, 1, is_daemon);

    return 0;
}
Something went wrong with that request. Please try again.