我正在尝试将 libcurl.dll 与 LuaJit 一起使用,但curl_easy_perform
总是返回CURLE_URL_MALFORMAT
(3)
这是我的实际代码(代码已修复):
url = [[http://static02.mediaite.com/geekosystem/uploads/2013/12/doge.jpg]]
ffi.cdef [[
int curl_version();
void *curl_easy_init();
int curl_easy_setopt(void *curl, int option, ...); // here was the error!
int curl_easy_perform(void *curl);
void curl_easy_cleanup(void *curl);
]]
function cb(ptr, size, nmemb, stream)
print("Data callback!\n") -- not even called once
local bytes = size*nmemb
local buf = ffi.new('char[?]', bytes+1)
ffi.copy(buf, ptr, bytes)
buf[bytes] = 0
data = ffi.string(buf)
return bytes
end
fptr = ffi.cast("size_t (*)(char *, size_t, size_t, void *)", cb)
data = ""
CURLOPT_URL = 10002
CURLOPT_WRITEFUNCTION = 20011
CURLOPT_VERBOSE = 41
libcurl = ffi.load("libcurl.dll")
print("cURL Version: ", libcurl.curl_version(), "\n")
curl = libcurl.curl_easy_init()
if curl then
print("Trying to download: ", url, "\n")
libcurl.curl_easy_setopt(curl, CURLOPT_VERBOSE, 1)
--libcurl.curl_easy_setopt(curl, CURLOPT_URL, ffi.cast("char *", url)) -- or this? both doesn't work
libcurl.curl_easy_setopt(curl, CURLOPT_URL, url)
libcurl.curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fptr)
print("Result: ", libcurl.curl_easy_perform(curl), "\n")
libcurl.curl_easy_cleanup(curl)
end
具有两个 .dll 版本的脚本的输出:
> dofile("curl.lua")
cURL Version: 1887658112
Trying to download: http://static02.mediaite.com/geekosystem/uploads/2013/12/doge.jpg
Result: 3
>
>
> dofile("curl.lua")
cURL Version: 1757089944
Trying to download: http://static02.mediaite.com/geekosystem/uploads/2013/12/doge.jpg
Result: 3
>
我对两个 .dll 进行了尝试,它们的行为相同。
我从以下位置下载的第二个 .dll:http: //www.confusedbycode.com/curl/curl-7.35.0-win32-fix1.zip
有人知道如何让 LuaJit/cURL 一起工作吗?