Reorganize examples tree.
parent
bf4b8b0b0b
commit
a50ffe9997
|
@ -4,7 +4,7 @@
|
||||||
-- RCS ID: $Id: browser.lua,v 0.1 2011/03/11 23:55:20 kai Exp $
|
-- RCS ID: $Id: browser.lua,v 0.1 2011/03/11 23:55:20 kai Exp $
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
local cURL = require("lcurl.cURL")
|
local cURL = require("cURL")
|
||||||
local string = require("string")
|
local string = require("string")
|
||||||
local table = require("table")
|
local table = require("table")
|
||||||
local base = _G
|
local base = _G
|
|
@ -1,4 +1,4 @@
|
||||||
local cURL = require("lcurl.cURL")
|
local cURL = require("cURL")
|
||||||
|
|
||||||
-- open output file
|
-- open output file
|
||||||
f = io.open("example_homepage", "w")
|
f = io.open("example_homepage", "w")
|
||||||
|
@ -7,9 +7,9 @@ c = cURL.easy_init()
|
||||||
-- setup url
|
-- setup url
|
||||||
c:setopt_url("http://www.example.com/")
|
c:setopt_url("http://www.example.com/")
|
||||||
-- perform, invokes callbacks
|
-- perform, invokes callbacks
|
||||||
c:perform({writefunction = function(str)
|
c:perform{writefunction = function(str)
|
||||||
f:write(str)
|
f:write(str)
|
||||||
end})
|
end}
|
||||||
|
|
||||||
-- close output file
|
-- close output file
|
||||||
f:close()
|
f:close()
|
|
@ -1,15 +1,15 @@
|
||||||
local cURL = require("lcurl.cURL")
|
local cURL = require("cURL")
|
||||||
|
|
||||||
-- setup easy
|
-- setup easy
|
||||||
c = cURL.easy_init()
|
c1 = cURL.easy_init()
|
||||||
c2 = cURL.easy_init()
|
c2 = cURL.easy_init()
|
||||||
|
|
||||||
-- setup url
|
-- setup url
|
||||||
c:setopt_url("http://www.lua.org/")
|
c1:setopt_url("http://www.lua.org/")
|
||||||
c2:setopt_url("http://luajit.org/")
|
c2:setopt_url("http://luajit.org/")
|
||||||
|
|
||||||
m = cURL.multi_init()
|
m = cURL.multi_init()
|
||||||
m:add_handle(c)
|
m:add_handle(c1)
|
||||||
m:add_handle(c2)
|
m:add_handle(c2)
|
||||||
|
|
||||||
local f1 = io.open("lua.html","a+")
|
local f1 = io.open("lua.html","a+")
|
||||||
|
@ -17,6 +17,6 @@ local f2 = io.open("luajit.html","a+")
|
||||||
|
|
||||||
for data, type, easy in m:perform() do
|
for data, type, easy in m:perform() do
|
||||||
-- if (type == "header") then print(data) end
|
-- if (type == "header") then print(data) end
|
||||||
if (type == "data" and c == easy) then f1:write(data) end
|
if (type == "data" and c1 == easy) then f1:write(data) end
|
||||||
if (type == "data" and c2 == easy) then f2:write(data) end
|
if (type == "data" and c2 == easy) then f2:write(data) end
|
||||||
end
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
local cURL = require("lcurl.cURL")
|
local cURL = require("cURL")
|
||||||
|
|
||||||
-- returns size and reader
|
-- returns size and reader
|
||||||
local function make_stream(ch, n, m)
|
local function make_stream(ch, n, m)
|
|
@ -1,6 +1,6 @@
|
||||||
-- use LuaExpat and Lua-CuRL together for On-The-Fly XML parsing
|
-- use LuaExpat and Lua-CuRL together for On-The-Fly XML parsing
|
||||||
local lxp = require("lxp")
|
local lxp = require("lxp")
|
||||||
local cURL = require("lcurl.cURL")
|
local cURL = require("cURL")
|
||||||
|
|
||||||
tags = {}
|
tags = {}
|
||||||
items = {}
|
items = {}
|
||||||
|
@ -14,12 +14,13 @@ function callback.StartElement(parser, tagname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function callback.CharacterData(parser, str)
|
function callback.CharacterData(parser, str)
|
||||||
if (tags[#tags -1] == "item") then
|
if (tags[#tags -1] == "item") then
|
||||||
--we are parsing a item, get rid of trailing whitespace
|
--we are parsing a item, get rid of trailing whitespace
|
||||||
items[#items][tags[#tags]] = string.gsub(str, "%s*$", "")
|
items[#items][tags[#tags]] = string.gsub(str, "%s*$", "")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function callback.EndElement(parser, tagname)
|
function callback.EndElement(parser, tagname)
|
||||||
--assuming well formed xml
|
--assuming well formed xml
|
||||||
tags[#tags] = nil
|
tags[#tags] = nil
|
Loading…
Reference in New Issue