demo.lua

Sun, 28 Nov 2010 14:23:44 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 28 Nov 2010 14:23:44 +0000
changeset 8
b8d3938d9307
parent 2
38f221e53215
permissions
-rw-r--r--

COPYING: Add MIT/X11 licence

require "lahttp"
require "multihttp"

local function mycallback(url, status, data)
	print("---------------");
	if status == 200 then -- HTTP OK
		print("Received the data from "..url..":");
		print(data)
	else
		print("Received HTTP error "..status.." while downloading from "..url);
	end
	print("---------------");
end

local function progresscallback(batch)
	print("Progress:");
	for url, progress in pairs(batch:progress()) do
		print(url..":");
		for statistic, value in pairs(progress) do
			print("", statistic..":  "..value);
		end
	end
	print("");
end

batch_download = multihttp.new(mycallback, { "http://www.google.com/", "http://example.com/" });

batch_download:set_progress_callback(progresscallback, 1); -- Call progresscallback every second

batch_download:download(true); -- true means "don't return until all downloads are finished"

mercurial