Esempio n. 1
0
static void luv_fs_event_cb(uv_fs_event_t* handle, const char* filename, int events, int status) {
  lua_State* L = luv_state(handle->loop);

  // err
  luv_status(L, status);

  // filename
  lua_pushstring(L, filename);

  // events
  lua_newtable(L);
  if (events & UV_RENAME) {
    lua_pushboolean(L, 1);
    lua_setfield(L, -2, "rename");
  }
  if (events & UV_CHANGE) {
    lua_pushboolean(L, 1);
    lua_setfield(L, -2, "change");
  }

  luv_call_callback(L, handle->data, LUV_FS_EVENT, 3);
}
Esempio n. 2
0
static void luv_read_cb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
  lua_State* L = luv_state(handle->loop);
  int nargs;

  if (nread > 0) {
    lua_pushnil(L);
    lua_pushlstring(L, buf->base, nread);
    nargs = 2;
  }

  free(buf->base);
  if (nread == 0) return;

  if (nread == UV_EOF) {
    nargs = 0;
  }
  else if (nread < 0) {
    luv_status(L, nread);
    nargs = 1;
  }

  luv_call_callback(L, handle->data, LUV_READ, nargs);
}
Esempio n. 3
0
static void luv_fs_poll_cb(uv_fs_poll_t* handle, int status, const uv_stat_t* prev, const uv_stat_t* curr) {
  lua_State* L = luv_state(handle->loop);

  // err
  luv_status(L, status);

  // prev
  if (prev) {
    luv_push_stats_table(L, prev);
  }
  else {
    lua_pushnil(L);
  }

  // curr
  if (curr) {
    luv_push_stats_table(L, curr);
  }
  else {
    lua_pushnil(L);
  }

  luv_call_callback(L, handle->data, LUV_FS_POLL, 3);
}
Esempio n. 4
0
static void luv_signal_cb(uv_signal_t* handle, int signum) {
  lua_State* L = luv_state(handle->loop);
  luv_handle_t* data = handle->data;
  lua_pushstring(L, luv_sig_num_to_string(signum));
  luv_call_callback(L, data, LUV_SIGNAL, 1);
}
Esempio n. 5
0
static void luv_idle_cb(uv_idle_t* handle) {
  lua_State* L = luv_state(handle->loop);
  luv_handle_t* data = (luv_handle_t*)handle->data;
  luv_call_callback(L, data, LUV_IDLE, 0);
}
Esempio n. 6
0
static void luv_connection_cb(uv_stream_t* handle, int status) {
  lua_State* L = luv_state(handle->loop);
  luv_status(L, status);
  luv_call_callback(L, handle->data, LUV_CONNECTION, 1);
}
Esempio n. 7
0
static void luv_prepare_cb(uv_prepare_t* handle) {
  lua_State* L = luv_state(handle->loop);
  luv_handle_t* data = handle->data;
  luv_call_callback(L, data, LUV_PREPARE, 0);
}