Simplify code of cURL module.
This commit is contained in:
parent
c2f8fc99f9
commit
e0dfc3a490
@ -32,21 +32,20 @@ local function wrap_setopt_flags(k, flags)
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------
|
||||
local Easy = {} do
|
||||
|
||||
Easy.__index = function(self, k)
|
||||
local fn = Easy[k]
|
||||
local function class(ctor)
|
||||
local C = {}
|
||||
C.__index = function(self, k)
|
||||
local fn = C[k]
|
||||
|
||||
if not fn and self._handle[k] then
|
||||
fn = wrap_function(k)
|
||||
self[k] = fn
|
||||
end
|
||||
return fn
|
||||
end
|
||||
end
|
||||
|
||||
function Easy:new()
|
||||
local h, err = curl.easy()
|
||||
function C:new()
|
||||
local h, err = ctor()
|
||||
if not h then return nil, err end
|
||||
|
||||
local o = setmetatable({
|
||||
@ -54,11 +53,17 @@ function Easy:new()
|
||||
}, self)
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
function C:handle()
|
||||
return self._handle
|
||||
end
|
||||
|
||||
return C
|
||||
end
|
||||
|
||||
function Easy:handle()
|
||||
return self._handle
|
||||
end
|
||||
-------------------------------------------
|
||||
local Easy = class(curl.easy) do
|
||||
|
||||
local perform = wrap_function("perform")
|
||||
local setopt_share = wrap_function("setopt_share")
|
||||
@ -196,33 +201,7 @@ end
|
||||
-------------------------------------------
|
||||
|
||||
-------------------------------------------
|
||||
local Multi = {} do
|
||||
|
||||
Multi.__index = function(self, k)
|
||||
local fn = Multi[k]
|
||||
|
||||
if not fn and self._handle[k] then
|
||||
fn = wrap_function(k)
|
||||
self[k] = fn
|
||||
end
|
||||
return fn
|
||||
end
|
||||
|
||||
function Multi:new()
|
||||
local h, err = curl.multi()
|
||||
if not h then return nil, err end
|
||||
|
||||
local o = setmetatable({
|
||||
_handle = h;
|
||||
_easy = {};
|
||||
}, self)
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
function Multi:handle()
|
||||
return self._handle
|
||||
end
|
||||
local Multi = class(curl.multi) do
|
||||
|
||||
local perform = wrap_function("perform")
|
||||
local add_handle = wrap_function("add_handle")
|
||||
@ -309,32 +288,7 @@ end
|
||||
-------------------------------------------
|
||||
|
||||
-------------------------------------------
|
||||
local Share = {} do
|
||||
|
||||
Share.__index = function(self, k)
|
||||
local fn = Share[k]
|
||||
|
||||
if not fn and self._handle[k] then
|
||||
fn = wrap_function(k)
|
||||
self[k] = fn
|
||||
end
|
||||
return fn
|
||||
end
|
||||
|
||||
function Share:new()
|
||||
local h, err = curl.share()
|
||||
if not h then return nil, err end
|
||||
|
||||
local o = setmetatable({
|
||||
_handle = h
|
||||
}, self)
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
function Share:handle()
|
||||
return self._handle
|
||||
end
|
||||
local Share = class(curl.share) do
|
||||
|
||||
Share.setopt_share = wrap_setopt_flags("share", {
|
||||
[ "COOKIE" ] = curl.LOCK_DATA_COOKIE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user