lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I have a problem using curl in lua. I would like to recover information from amazon in order to populate a book database.

I tried using luacurl ( as follow:


filename = "databook.txt"
f = assert(, "w"))

c =
c:setopt(curl.OPT_URL, "") -- 1558607986 is isbn of the book
c:setopt(curl.OPT_HTTPGET, true)
c:setopt(curl.OPT_ENCODING, "utf8")
c:setopt(curl.OPT_WRITEFUNCTION, function(userparam, buffer) f:write(buffer) end)


It works well in the terminal as I see all the html code, but if I uncomment the callback function, I only get 4kb of data (that is only a small part of what I received in the terminal).

I also tried using lua-curl ( as follow:


-- open output file
filename = "databook.txt"
f = assert(, "w"))

c = cURL.easy_init()
-- setup url
-- perform, invokes callbacks
c:perform({writefunction = function(str) f:write(str) end})

-- close output file

and it seems to work both with and without callback function. However, I get the following message at the end :

"bash ~/projects/DB $> ./test.lua
lua(241) malloc: ***  Deallocation of a pointer not malloced: 0x3ce00; This could be a double free(), or free() called with the middle of an allocated block; Try setting environment variable MallocHelp to see tools to help debug"

I'm no expert in programming and new to lua, so I'm not sure how to react :-s

Could anyone explain me how to fix first version ? I would prefer that one because luacurl is tagged as stable whereas lua-curl is pre-alpha.