diff options
Diffstat (limited to 'samples/cddb.lua')
-rw-r--r-- | samples/cddb.lua | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/samples/cddb.lua b/samples/cddb.lua index 482dc98..883730c 100644 --- a/samples/cddb.lua +++ b/samples/cddb.lua | |||
@@ -16,7 +16,7 @@ function parse(body) | |||
16 | return nil, code, message | 16 | return nil, code, message |
17 | end | 17 | end |
18 | local data = {} | 18 | local data = {} |
19 | for l in lines do | 19 | for l in lines do |
20 | local c = string.sub(l, 1, 1) | 20 | local c = string.sub(l, 1, 1) |
21 | if c ~= '#' and c ~= '.' then | 21 | if c ~= '#' and c ~= '.' then |
22 | local key, value = socket.skip(2, string.find(l, "(.-)=(.*)")) | 22 | local key, value = socket.skip(2, string.find(l, "(.-)=(.*)")) |
@@ -26,7 +26,7 @@ function parse(body) | |||
26 | data[key] = value | 26 | data[key] = value |
27 | end | 27 | end |
28 | end | 28 | end |
29 | return data, code, message | 29 | return data, code, message |
30 | end | 30 | end |
31 | 31 | ||
32 | local host = socket.dns.gethostname() | 32 | local host = socket.dns.gethostname() |
@@ -34,13 +34,13 @@ local query = "%s?cmd=cddb+read+%s+%s&hello=LuaSocket+%s+LuaSocket+2.0&proto=6" | |||
34 | local url = string.format(query, server, arg[1], arg[2], host) | 34 | local url = string.format(query, server, arg[1], arg[2], host) |
35 | local body, headers, code = http.get(url) | 35 | local body, headers, code = http.get(url) |
36 | 36 | ||
37 | if code == 200 then | 37 | if code == 200 then |
38 | local data, code, error = parse(body) | 38 | local data, code, error = parse(body) |
39 | if not data then | 39 | if not data then |
40 | print(error or code) | 40 | print(error or code) |
41 | else | 41 | else |
42 | for i,v in pairs(data) do | 42 | for i,v in pairs(data) do |
43 | io.write(i, ': ', v, '\n') | 43 | io.write(i, ': ', v, '\n') |
44 | end | 44 | end |
45 | end | 45 | end |
46 | else print(error) end | 46 | else print(error) end |