Change. optional argument for easy:perform in Lua-cURL interface.

master
Alexey Melnichuk 2014-09-04 13:07:54 +05:00
parent 933c84db7d
commit f0c8ca020f
2 changed files with 21 additions and 18 deletions

View File

@ -1,47 +1,49 @@
local cURL = require("lcurl.cURL")
-- returns size and reader
local function make_stream(ch, n, m)
local size = n * m
local i = -1
return size, function()
i = i + 1
if i < m then
return (tostring(ch)):rep(n - 2) .. '\r\n'
end
end
end
c = cURL.easy_init()
c:setopt_url("http://posttestserver.com/post.php")
c:setopt_post(true)
local length, reader = make_stream("a", 10, 4)
c:post{-- post file from private read function
-- Lua-cURL compatiable
-- allows only one stream
name = {
file="stream.txt",
stream_length="5",
stream_length=length,
type="text/plain",
}
}
count = 0
c:perform{readfunction = function(n)
if count < 5 then
count = 5
return "stream"
end
return nil
end}
c:perform{readfunction = reader}
local length, reader = make_stream("b", 10, 4)
c:post{-- post file from private read function
-- define stream callback
name = {
file = "stream.txt",
type = "text/plain",
stream_length = 5,
stream = function()
if count < 5 then
count = 5
return "STREAM"
end
return nil
end,
stream_length = length,
stream = reader,
}
}
count = 0
c:perform{}
print("Done")

View File

@ -83,6 +83,7 @@ function Easy:setopt_readfunction(fn, ...)
end
function Easy:perform(opt)
opt = opt or {}
local oerror = opt.errorfunction or function(err) return nil, err end