static void luv_connect_cb(uv_connect_t* req, int status) { lua_State* L = luv_state(req->handle->loop); luv_status(L, status); luv_fulfill_req(L, req->data, 1); luv_cleanup_req(L, req->data); req->data = NULL; }
static void luv_poll_cb(uv_poll_t* handle, int status, int events) { lua_State* L = luv_state(handle->loop); luv_handle_t* data = (luv_handle_t*)handle->data; const char* evtstr; if (status < 0) { fprintf(stderr, "%s: %s\n", uv_err_name(status), uv_strerror(status)); lua_pushstring(L, uv_err_name(status)); } else { lua_pushnil(L); } switch (events) { case UV_READABLE: evtstr = "r"; break; case UV_WRITABLE: evtstr = "w"; break; case UV_READABLE|UV_WRITABLE: evtstr = "rw"; break; case UV_DISCONNECT: evtstr = "d"; break; case UV_READABLE|UV_DISCONNECT: evtstr = "rd"; break; case UV_WRITABLE|UV_DISCONNECT: evtstr = "wd"; break; case UV_READABLE|UV_WRITABLE|UV_DISCONNECT: evtstr = "rwd"; break; default: evtstr = ""; break; } lua_pushstring(L, evtstr); luv_call_callback(L, data, LUV_POLL, 2); }
static void exit_cb(uv_process_t* handle, int64_t exit_status, int term_signal) { lua_State* L = luv_state(handle->loop); luv_handle_t* data = handle->data; lua_pushinteger(L, exit_status); lua_pushinteger(L, term_signal); luv_call_callback(L, data, LUV_EXIT, 2); }
static void svcdispatcher_end_cb(uv_async_t* handle) { svc_dispatch_info *info = (svc_dispatch_info*)handle->data; lua_State* L = luv_state(handle->loop); /* Cleanup baton linked list */ svc_baton *svc_baton_it = gBatons; while (svc_baton_it != NULL) { svc_baton *old = svc_baton_it; svc_baton_it = svc_baton_it->next; svc_destroy_baton(L, old); } uv_close((uv_handle_t*)&info->end_async_handle, NULL); gBatons = NULL; lua_rawgeti(L, LUA_REGISTRYINDEX, info->lua_cb_ref); lua_pushboolean(L, info->return_code); if (info->return_code) { lua_pushnil(L); } else { lua_pushinteger(L, info->error); } lua_call(L, 2, 0); luaL_unref(L, LUA_REGISTRYINDEX, info->lua_cb_ref); LocalFree(info->svc_table); LocalFree(info); }
static void luv_udp_send_cb(uv_udp_send_t* req, int status) { lua_State* L = luv_state(req->handle->loop); luv_status(L, status); luv_fulfill_req(L, (luv_req_t*)req->data, 1); luv_cleanup_req(L, (luv_req_t*)req->data); req->data = NULL; }
static void luv_close_cb(uv_handle_t* handle) { lua_State* L = luv_state(handle->loop); luv_handle_t* data = handle->data; if (!data) return; luv_call_callback(L, data, LUV_CLOSED, 0); luv_cleanup_handle(L, data); handle->data = NULL; }
static void svcmain_cb(uv_async_t* handle) { lua_State* L = luv_state(handle->loop); svc_baton* baton = handle->data; lua_pushstring(L, "winsvc_error_cb"); lua_gettable(L, LUA_REGISTRYINDEX); lua_rawgeti(L, LUA_REGISTRYINDEX, baton->lua_main_ref); lua_newtable(L); for (unsigned int i = 0; i < baton->dwArgc; i++) { lua_pushnumber(L, i + 1); /* Push the table index */ lua_pushstring(L, baton->lpszArgv[i]); /* Push the cell value */ lua_rawset(L, -3); /* Stores the pair in the table */ } lua_pushlightuserdata(L, baton); lua_pcall(L, 2, 0, -4); }
static void luv_udp_recv_cb(uv_udp_t* handle, ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned flags) { lua_State* L = luv_state(handle->loop); // err if (nread < 0) { luv_status(L, nread); } else { lua_pushnil(L); } // data if (nread == 0) { if (addr) { lua_pushstring(L, ""); } else { lua_pushnil(L); } } else if (nread > 0) { lua_pushlstring(L, buf->base, nread); } else { lua_pushnil(L); } if (buf) free(buf->base); // address if (addr) { parse_sockaddr(L, (struct sockaddr_storage*)addr); } else { lua_pushnil(L); } // flags lua_newtable(L); if (flags & UV_UDP_PARTIAL) { lua_pushboolean(L, 1); lua_setfield(L, -2, "partial"); } luv_call_callback(L, (luv_handle_t*)handle->data, LUV_RECV, 4); }
static void luv_getaddrinfo_cb(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { lua_State* L = luv_state(req->loop); int nargs; if (status < 0) { luv_status(L, status); nargs = 1; } else { lua_pushnil(L); luv_pushaddrinfo(L, res); nargs = 2; } luv_fulfill_req(L, (luv_req_t*)req->data, nargs); luv_cleanup_req(L, (luv_req_t*)req->data); req->data = NULL; if (res) uv_freeaddrinfo(res); }
static void svchandler_cb(uv_async_t* handle) { lua_State* L = luv_state(handle->loop); svc_baton* baton = handle->data; lua_pushstring(L, "winsvc_error_cb"); lua_gettable(L, LUA_REGISTRYINDEX); lua_rawgeti(L, LUA_REGISTRYINDEX, baton->block.lua_cb_ref); lua_pushinteger(L, baton->block.dwControl); lua_pushinteger(L, baton->block.dwEventType); lua_pushlightuserdata(L, baton->block.lpEventData); lua_pushlightuserdata(L, baton->block.lpContext); if (lua_pcall(L, 4, 1, -6) == 0) { baton->block.return_code = luaL_checkint(L, -1); } else { baton->block.return_code = ERROR; } SetEvent(baton->block.block_end_event); }
static void luv_getnameinfo_cb(uv_getnameinfo_t* req, int status, const char* hostname, const char* service) { lua_State* L = luv_state(req->loop); int nargs; if (status < 0) { luv_status(L, status); nargs = 1; } else { lua_pushnil(L); lua_pushstring(L, hostname); lua_pushstring(L, service); nargs = 3; } luv_fulfill_req(L, (luv_req_t*)req->data, nargs); luv_cleanup_req(L, (luv_req_t*)req->data); req->data = NULL; }
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); }
static void luv_fs_cb(uv_fs_t* req) { lua_State* L = luv_state(req->loop); int nargs = push_fs_result(L, req); if (nargs == 2 && lua_isnil(L, -nargs)) { // If it was an error, convert to (err, value) format. lua_remove(L, -nargs); nargs--; } else { // Otherwise insert a nil in front to convert to (err, value) format. lua_pushnil(L); lua_insert(L, -nargs - 1); nargs++; } luv_fulfill_req(L, req->data, nargs); if (req->fs_type != UV_FS_SCANDIR) { luv_cleanup_req(L, req->data); req->data = NULL; uv_fs_req_cleanup(req); } }
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); }
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); }
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); }
static void luv_spawn_close_cb(uv_handle_t* handle) { lua_State *L = luv_state(handle->loop); luv_cleanup_handle(L, handle->data); }
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); }
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); }
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); }