Add. getinfo method

This commit is contained in:
Alexey Melnichuk 2014-08-27 10:34:11 +05:00
parent 70af182080
commit 9d36abc5d6
2 changed files with 32 additions and 2 deletions

View File

@ -134,13 +134,28 @@ function easy:close() end
--- Set options.
--
-- @tparam number opt one of `curl.OPT_XXX` constant
-- @params ... value
-- @param ... value
-- @treturn easy self
--
-- @usage
-- c:setopt(curl.OPT_URL, "http://example.com")
-- c:setopt(curl.OPT_READFUNCTION, function(t, n) return table.remove(t) end, {"1111", "2222"})
-- c:setopt(curl.OPT_READFUNCTION,
-- function(t, n) return table.remove(t) end,
-- {"1111", "2222"}
-- )
function easy:setopt() end
--- Get information.
--
-- @tparam number info one of `curl.INFO_XXX` constant
-- @return value
--
-- @usage
-- print(c:getinfo(curl.INFO_EFFECTIVE_URL))
-- print(c:getinfo(curl.INFO_TOTAL_TIME))
-- print(c:getinfo(curl.INFO_RESPONSE_CODE))
function easy:getinfo() end
--- Set writer function.
--
-- A callback accepting one or two parameters.

View File

@ -650,6 +650,20 @@ static int lcurl_easy_setopt(lua_State *L){
return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, CURLE_UNKNOWN_OPTION);
}
static int lcurl_easy_getinfo(lua_State *L){
lcurl_easy_t *p = lcurl_geteasy(L);
int opt = luaL_checklong(L, 2);
lua_remove(L, 2);
#define OPT_ENTRY(l, N, T, S) case CURLINFO_##N: return lcurl_easy_get_##N(L);
switch(opt){
#include "lcinfoeasy.h"
}
#undef OPT_ENTRY
return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, CURLE_UNKNOWN_OPTION);
}
//}
static const struct luaL_Reg lcurl_easy_methods[] = {
@ -669,6 +683,7 @@ static const struct luaL_Reg lcurl_easy_methods[] = {
#undef OPT_ENTRY
{ "setopt", lcurl_easy_setopt },
{ "getinfo", lcurl_easy_getinfo },
{ "escape", lcurl_easy_escape },
{ "unescape", lcurl_easy_unescape },
{ "perform", lcurl_easy_perform },