Exemplo n.º 1
0
static void on_redis_response(redisAsyncContext *context, void *reply, void *privdata)
{
  redisReply *redisReply = reply;
  luv_ref_t *ref = privdata;
  int replyArgsCount = 0;

  lua_State *L = ref->L;
  lua_rawgeti(L, LUA_REGISTRYINDEX, ref->r);
  luaL_unref(L, LUA_REGISTRYINDEX, ref->r);
  ref_free(ref);

  if (redisReply == NULL)
  {
    luv_push_async_hiredis_error(L, context, "on_redis_response");
    lua_pushnil(L);
    luv_acall(L, 2, 0, "on_redis_response");
  }
  else
  {
    if (redisReply->type != REDIS_REPLY_ERROR)
    {
      lua_pushnil(L);
      ++replyArgsCount;
    }
    replyArgsCount += push_reply(L, redisReply);
    luv_acall(L, replyArgsCount, 0, "on_redis_response");
  }
}
Exemplo n.º 2
0
static void luv_on_udp_send(uv_udp_send_t* req, int status) {
  luv_udp_ref_t *ref;
  /* load the lua state and the userdata */
  lua_State *L = luv_handle_get_lua(req->handle->data);
  lua_pop(L, 1); /* We don't need the userdata */
  /* load the callback */
  ref =  req->data;
  lua_rawgeti(L, LUA_REGISTRYINDEX, ref->ref);
  luaL_unref(L, LUA_REGISTRYINDEX, ref->ref);
  free(ref);

  if (lua_isfunction(L, -1)) {
    if (status != 0) {
      luv_push_async_error(L, uv_last_error(luv_get_loop(L)), "on_udp_send", NULL);
      luv_acall(L, 1, 0, "on_udp_send");
    } else {
      luv_acall(L, 0, 0, "on_udp_send");
    }
  } else {
    lua_pop(L, 1);
  }

  luv_handle_unref(L, req->handle->data);
  free(req);
}
Exemplo n.º 3
0
void luv_after_fs(uv_fs_t* req) {
  luv_fs_ref_t* ref = req->data;
  lua_State *L = ref->L;
  int argc;

  luv_io_ctx_callback_rawgeti(L, &ref->cbs);
  luv_io_ctx_unref(L, &ref->cbs);

  argc = luv_process_fs_result(L, req);

  luv_acall(L, argc + 1, 0, "fs_after");

  uv_fs_req_cleanup(req);
  free(ref); /* We're done with the ref object, free it */
}
Exemplo n.º 4
0
Arquivo: luv_fs.c Projeto: nko/luvit
void luv_after_fs(uv_fs_t* req) {
    luv_fs_ref_t* ref = req->data;
    lua_State *L = ref->L;
    int before = lua_gettop(L);
    lua_rawgeti(L, LUA_REGISTRYINDEX, ref->r);
    luaL_unref(L, LUA_REGISTRYINDEX, ref->r);

    int argc = luv_process_fs_result(L, req);

    luv_acall(L, argc + 1, 0, "fs_after");

    uv_fs_req_cleanup(req);
    free(ref);// We're done with the ref object, free it
    assert(lua_gettop(L) == before);
}
Exemplo n.º 5
0
/* Emit an event of the current userdata consuming nargs
 * Assumes userdata is right below args
 */
void luv_emit_event(lua_State* L, const char* name, int nargs) {
    /* Load the connection callback */
    lua_getfenv(L, -nargs - 1);
    lua_getfield(L, -1, name);
    /* remove the userdata environment */
    lua_remove(L, -2);
    /* Remove the userdata */
    lua_remove(L, -nargs - 2);

    if (lua_isfunction (L, -1) == 0) {
        lua_pop(L, 1 + nargs);
        return;
    }


    /* move the function below the args */
    lua_insert(L, -nargs - 1);
    luv_acall(L, nargs, 0, name);
}
Exemplo n.º 6
0
// Emit an event of the current userdata consuming nargs
// Assumes userdata is right below args
void luv_emit_event(lua_State* L, const char* name, int nargs) {
  int before = lua_gettop(L);
  // Load the connection callback
  lua_getfenv(L, -nargs - 1);
  lua_getfield(L, -1, name);
  // remove the userdata environment
  lua_remove(L, -2);
  // Remove the userdata
  lua_remove(L, -nargs - 2);

  if (lua_isfunction (L, -1) == 0) {
    lua_pop(L, 1 + nargs);
    assert(lua_gettop(L) == before - nargs - 1);
    return;
  }


  // move the function below the args
  lua_insert(L, -nargs - 1);
  luv_acall(L, nargs, 0, name);

  assert(lua_gettop(L) == before - nargs - 1);
}