コード例 #1
0
ファイル: lluv_tcp.c プロジェクト: moteus/lua-lluv
static lluv_handle_t* lluv_check_tcp(lua_State *L, int idx, lluv_flags_t flags){
  lluv_handle_t *handle = lluv_check_stream(L, idx, LLUV_FLAG_OPEN);
  luaL_argcheck (L, LLUV_H(handle, uv_handle_t)->type == UV_TCP, idx, LLUV_TCP_NAME" expected");

  luaL_argcheck (L, FLAGS_IS_SET(handle->flags, flags), idx, LLUV_TCP_NAME" closed");
  return handle;
}
コード例 #2
0
ファイル: lluv_process.c プロジェクト: yinlei/lua-lluv
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);
}