Пример #1
0
void lcurl_error_initlib(lua_State *L, int nup){
  if(!lutil_createmetap(L, LCURL_ERROR, lcurl_err_methods, nup))
    lua_pop(L, nup);
  lua_pop(L, 1);

  lcurl_util_set_const(L, lcurl_error_codes);
  lcurl_util_set_const(L, lcurl_error_category);
}
Пример #2
0
void lcurl_share_initlib(lua_State *L, int nup){
  if(!lutil_createmetap(L, LCURL_SHARE, lcurl_share_methods, nup))
    lua_pop(L, nup);
  lua_pop(L, 1);

  lcurl_util_set_const(L, lcurl_share_opt);
}
Пример #3
0
static int luaopen_lcurl_(lua_State *L, const struct luaL_Reg *func){
  if(!LCURL_INIT){
    /* Note from libcurl documentation.
     *
     * The environment it sets up is constant for the life of the program
     * and is the same for every program, so multiple calls have the same
     * effect as one call. ... This function is not thread safe.
     */
    curl_global_init(CURL_GLOBAL_DEFAULT);
    LCURL_INIT = 1;
  }

  lua_rawgetp(L, LUA_REGISTRYINDEX, LCURL_REGISTRY);
  if(!lua_istable(L, -1)){ /* registry */
    lua_pop(L, 1);
    lua_newtable(L);
  }

  lua_rawgetp(L, LUA_REGISTRYINDEX, LCURL_USERVAL);
  if(!lua_istable(L, -1)){ /* usevalues */
    lua_pop(L, 1);
    lcurl_util_new_weak_table(L, "k");
  }

#if LCURL_CURL_VER_GE(7,56,0)
  lua_rawgetp(L, LUA_REGISTRYINDEX, LCURL_MIME_EASY_MAP);
  if(!lua_istable(L, -1)){ /* Mime->Easy */
    lua_pop(L, 1);
    lcurl_util_new_weak_table(L, "v");
  }
#endif

  lua_newtable(L); /* library  */

  LCURL_PUSH_NUP(L); luaL_setfuncs(L, func, NUP);
  LCURL_PUSH_NUP(L); lcurl_error_initlib(L, NUP);
  LCURL_PUSH_NUP(L); lcurl_hpost_initlib(L, NUP);
  LCURL_PUSH_NUP(L); lcurl_easy_initlib (L, NUP);
  LCURL_PUSH_NUP(L); lcurl_mime_initlib (L, NUP);
  LCURL_PUSH_NUP(L); lcurl_multi_initlib(L, NUP);
  LCURL_PUSH_NUP(L); lcurl_share_initlib(L, NUP);

  LCURL_PUSH_NUP(L);

#if LCURL_CURL_VER_GE(7,56,0)
  lua_rawsetp(L, LUA_REGISTRYINDEX, LCURL_MIME_EASY_MAP);
#endif

  lua_rawsetp(L, LUA_REGISTRYINDEX, LCURL_USERVAL);
  lua_rawsetp(L, LUA_REGISTRYINDEX, LCURL_REGISTRY);

  lcurl_util_set_const(L, lcurl_flags);

  lutil_push_null(L);
  lua_setfield(L, -2, "null");

  return 1;
}
Пример #4
0
void lcurl_url_initlib(lua_State *L, int nup){
#if LCURL_CURL_VER_GE(7,62,0)
  if(!lutil_createmetap(L, LCURL_URL, lcurl_url_methods, nup))
    lua_pop(L, nup);
  lua_pop(L, 1);

  lcurl_util_set_const(L, lcurl_url_opt);
#else
  lua_pop(L, nup);
#endif
}
Пример #5
0
static int luaopen_lcurl_(lua_State *L, const struct luaL_Reg *func){
  if(!LCURL_INIT){
    curl_global_init(CURL_GLOBAL_DEFAULT);
    LCURL_INIT = 1;
  }

  lua_rawgetp(L, LUA_REGISTRYINDEX, LCURL_REGISTRY);
  if(!lua_istable(L, -1)){ /* registry */
    lua_pop(L, 1);
    lua_newtable(L);
  }

  lua_rawgetp(L, LUA_REGISTRYINDEX, LCURL_USERVAL);
  if(!lua_istable(L, -1)){ /* usevalues */
    lua_pop(L, 1);
    lcurl_util_new_weak_table(L, "k");
  }

  lua_newtable(L); /* library  */

  lua_pushvalue(L, -3); lua_pushvalue(L, -3); luaL_setfuncs(L, func, 2);
  lua_pushvalue(L, -3); lua_pushvalue(L, -3); lcurl_error_initlib(L, 2);
  lua_pushvalue(L, -3); lua_pushvalue(L, -3); lcurl_hpost_initlib(L, 2);
  lua_pushvalue(L, -3); lua_pushvalue(L, -3); lcurl_easy_initlib (L, 2);
  lua_pushvalue(L, -3); lua_pushvalue(L, -3); lcurl_multi_initlib(L, 2);
  lua_pushvalue(L, -3); lua_pushvalue(L, -3); lcurl_share_initlib(L, 2);

  lua_pushvalue(L, -3); lua_rawsetp(L, LUA_REGISTRYINDEX, LCURL_REGISTRY);
  lua_pushvalue(L, -2); lua_rawsetp(L, LUA_REGISTRYINDEX, LCURL_USERVAL);

  lua_remove(L, -2); /* registry */

  lcurl_util_set_const(L, lcurl_flags);

  return 1;
}