LLUV_INTERNAL lluv_req_t* lluv_req_new(lua_State *L, uv_req_type type, lluv_handle_t *h){ size_t extra_size = uv_req_size(type) - sizeof(uv_req_t); lluv_req_t *req = (lluv_req_t*)lluv_alloc(L, sizeof(lluv_req_t) + extra_size); req->req.data = req; req->handle = h; req->cb = luaL_ref(L, LLUV_LUA_REGISTRY); req->arg = LUA_NOREF; req->ctx = LUA_NOREF; if(h) lluv_handle_lock(L, h, LLUV_LOCK_REQ); return req; }
static void opt_get_stdio(lua_State *L, int idx, uv_process_options_t *opt){ static const lluv_uv_const_t FLAGS[] = { { UV_IGNORE, "ignore" }, { UV_CREATE_PIPE, "create_pipe" }, { UV_INHERIT_FD, "inherit_fd" }, { UV_INHERIT_STREAM, "inherit_stream" }, { UV_READABLE_PIPE, "readable_pipe" }, { UV_WRITABLE_PIPE, "writable_pipe" }, { 0, NULL } }; size_t i, n; rawgets(L, idx, "stdio"); if(lua_isnil(L, -1)){ lua_settop(L, 1); return; } if(!lua_istable(L, -1)){ lua_pop(L, 1); lua_pushstring(L, "stdio option must be an array"); lua_error(L); return; } n = lua_objlen(L, -1); if(n == 0){ lua_pop(L, 1); return; } opt->stdio = lluv_alloc(L, n * sizeof(*opt->stdio)); opt->stdio_count = n; for(i = 0; i < n; ++i){ lua_rawgeti(L, -1, i + 1); if(lua_istable(L, -1)){ uv_stdio_flags flags = 0; if(opt_exists(L, -1, "fd")){ opt->stdio[i].data.fd = (int)opt_get_int64 (L, -1, "fd", 0, "stdio.fd option must be a number" ); flags = UV_INHERIT_FD; } else if(opt_exists(L, -1, "stream")){ lluv_handle_t *handle; rawgets(L, -1, "stream"); handle = lluv_check_stream(L, -1, LLUV_FLAG_OPEN); lua_pop(L, 1); opt->stdio[i].data.stream = LLUV_H(handle, uv_stream_t); flags = UV_INHERIT_STREAM; } else{ opt->stdio[i].data.fd = 0; flags = UV_IGNORE; } if(opt_exists(L, -1, "flags")){ rawgets(L, -1, "flags"); flags = lluv_opt_flags_ui(L, -1, 0, FLAGS); lua_pop(L, 1); // flags = opt_get_int64 (L, -1, "flags", 0, "stdio.flags option must be a number" ); } opt->stdio[i].flags = flags; } else if(lua_isnumber(L, -1)){ opt->stdio[i].data.fd = (int)lutil_checkint64(L, -1); opt->stdio[i].flags = UV_INHERIT_FD; } else if(lua_isuserdata(L, -1)){ lluv_handle_t *handle = lluv_check_stream(L, -1, LLUV_FLAG_OPEN); opt->stdio[i].data.stream = LLUV_H(handle, uv_stream_t); opt->stdio[i].flags = UV_INHERIT_STREAM; } else{ lua_pushstring(L, "stdio element must be table, stream or number"); lua_error(L); return; } lua_pop(L, 1); } lua_pop(L, 1); }