lua-users home
lua-l archive

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



Hi,

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 (http://luaforge.net/projects/luacurl/) as follow:

-----------------------------------------------
require("luacurl")

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

c = curl.new()
c:setopt(curl.OPT_URL, "http://www.amazon.fr/gp/product/1558607986") -- 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)
--]]
c:perform()
c:close()

io.close(f)
-----------------------------------------------

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 (http://luaforge.net/projects/lua-curl/) as follow:

-----------------------------------------------
require("cURL")

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

c = cURL.easy_init()
-- setup url
c:setopt_url("http://www.amazon.fr/gp/product/1558607986")
-- perform, invokes callbacks
c:perform({writefunction = function(str) f:write(str) end})

-- close output file
f:close()
print("Done")
-----------------------------------------------

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
Done
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.

--
Philippe