diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2011-09-22 13:49:53 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2011-09-22 13:50:30 +0200 |
commit | 8a901ee2447e2a2f4f3abdd57bd67dbe5c575812 (patch) | |
tree | ce00370b3933745891d0c58c49c77efc5b48b5c9 /pingu.lua | |
parent | f1d03e76ef1a192002f226c747fa2003c2e96f0b (diff) | |
download | pingu-8a901ee2447e2a2f4f3abdd57bd67dbe5c575812.tar.bz2 pingu-8a901ee2447e2a2f4f3abdd57bd67dbe5c575812.tar.xz |
lua: added initial lua client
Diffstat (limited to 'pingu.lua')
-rw-r--r-- | pingu.lua | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/pingu.lua b/pingu.lua new file mode 100644 index 0000000..02c3bb6 --- /dev/null +++ b/pingu.lua @@ -0,0 +1,39 @@ + +module(..., package.seeall) + + +local function status(self) + self.handle:write("status\n") + self.handle:flush() + + local t = {} + local line = self.handle:read("*line") + while line ~= "" do + local host, status = string.match(line, "^(.*): (.*)$") + t[host] = status + line = self.handle:read("*line") + end + return t +end + +local function close(self) + return self.handle:close() +end + +function connect(socket_path) + local socket = require("pingu.client") + local fh, err + if socket ~= nil then + fh, err = socket.open(socket_path) + end + if fh == nil then + return fh, err + end + return { + ["handle"] = fh, + ["status"] = status, + ["close"] = close + } +end + + |