Add. category
method to error object.
This commit is contained in:
parent
3ac4b54851
commit
ef25a2f444
@ -121,6 +121,17 @@ end
|
|||||||
-- @type error
|
-- @type error
|
||||||
--
|
--
|
||||||
do
|
do
|
||||||
|
|
||||||
|
--- Get the error category.
|
||||||
|
--
|
||||||
|
-- @treturn number number of error category (curl.ERROR_XXX constants)
|
||||||
|
--
|
||||||
|
-- @usage
|
||||||
|
-- if err:category() == curl.ERROR_EASY then
|
||||||
|
-- -- proceed easy error
|
||||||
|
-- end
|
||||||
|
function category ()end
|
||||||
|
|
||||||
--- Get the number value of error.
|
--- Get the number value of error.
|
||||||
--
|
--
|
||||||
-- @treturn number number of error (curl.E_XXX constants)
|
-- @treturn number number of error (curl.E_XXX constants)
|
||||||
|
@ -156,6 +156,12 @@ static int lcurl_err_equal(lua_State *L){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int lcurl_err_category(lua_State *L){
|
||||||
|
lcurl_error_t *err = lcurl_geterror(L);
|
||||||
|
lua_pushinteger(L, err->tp);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//{
|
//{
|
||||||
@ -199,6 +205,8 @@ static const struct luaL_Reg lcurl_err_methods[] = {
|
|||||||
{"msg", lcurl_err_msg },
|
{"msg", lcurl_err_msg },
|
||||||
{"name", lcurl_err_mnemo },
|
{"name", lcurl_err_mnemo },
|
||||||
{"mnemo", lcurl_err_mnemo },
|
{"mnemo", lcurl_err_mnemo },
|
||||||
|
{"cat", lcurl_err_category },
|
||||||
|
{"category", lcurl_err_category },
|
||||||
{"__tostring", lcurl_err_tostring },
|
{"__tostring", lcurl_err_tostring },
|
||||||
{"__eq", lcurl_err_equal },
|
{"__eq", lcurl_err_equal },
|
||||||
|
|
||||||
@ -226,6 +234,15 @@ static const lcurl_const_t lcurl_error_codes[] = {
|
|||||||
{NULL, 0}
|
{NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const lcurl_const_t lcurl_error_category[] = {
|
||||||
|
{"ERROR_CURL", LCURL_ERROR_CURL},
|
||||||
|
{"ERROR_EASY", LCURL_ERROR_EASY},
|
||||||
|
{"ERROR_MULTI", LCURL_ERROR_MULTI},
|
||||||
|
{"ERROR_SHARE", LCURL_ERROR_SHARE},
|
||||||
|
{"ERROR_FORM", LCURL_ERROR_FORM},
|
||||||
|
|
||||||
|
{NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
void lcurl_error_initlib(lua_State *L, int nup){
|
void lcurl_error_initlib(lua_State *L, int nup){
|
||||||
if(!lutil_createmetap(L, LCURL_ERROR, lcurl_err_methods, nup))
|
if(!lutil_createmetap(L, LCURL_ERROR, lcurl_err_methods, nup))
|
||||||
@ -233,4 +250,5 @@ void lcurl_error_initlib(lua_State *L, int nup){
|
|||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lcurl_util_set_const(L, lcurl_error_codes);
|
lcurl_util_set_const(L, lcurl_error_codes);
|
||||||
|
lcurl_util_set_const(L, lcurl_error_category);
|
||||||
}
|
}
|
||||||
|
@ -161,12 +161,6 @@ static const lcurl_const_t lcurl_flags[] = {
|
|||||||
#include "lcflags.h"
|
#include "lcflags.h"
|
||||||
#undef FLG_ENTRY
|
#undef FLG_ENTRY
|
||||||
|
|
||||||
"ERROR_CURL", LCURL_ERROR_CURL,
|
|
||||||
"ERROR_EASY", LCURL_ERROR_EASY,
|
|
||||||
"ERROR_MULTI", LCURL_ERROR_MULTI,
|
|
||||||
"ERROR_SHARE", LCURL_ERROR_SHARE,
|
|
||||||
"ERROR_FORM", LCURL_ERROR_FORM,
|
|
||||||
|
|
||||||
{NULL, 0}
|
{NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,4 +65,24 @@ end
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local _ENV = TEST_CASE'error_object' do
|
||||||
|
|
||||||
|
local curl = require "lcurl"
|
||||||
|
|
||||||
|
function test()
|
||||||
|
local e1 = curl.error(curl.ERROR_EASY, 0) -- ok
|
||||||
|
assert_equal(curl.ERROR_EASY, e1:category())
|
||||||
|
assert_equal(curl.E_OK, e1:no())
|
||||||
|
assert_equal("OK", e1:name())
|
||||||
|
|
||||||
|
local e2 = curl.error(curl.ERROR_MULTI, 0) -- ok
|
||||||
|
local e3 = curl.error(curl.ERROR_MULTI, 0) -- ok
|
||||||
|
assert_equal(0, e1:no())
|
||||||
|
assert_equal(0, e2:no())
|
||||||
|
assert(e1 ~= e2)
|
||||||
|
assert(e3 == e2)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
if not HAS_RUNNER then lunit.run() end
|
if not HAS_RUNNER then lunit.run() end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user