clix/raw.lua

changeset 19
3a0a156e0a79
child 23
c5f04bdc7c64
equal deleted inserted replaced
18:6ad3ea055905 19:3a0a156e0a79
1 short_opts.i = "interactive";
2 short_opts.e = "echo";
3
4 return function (opts, args)
5 local function on_connect(conn)
6 conn:hook("incoming-raw", print);
7 io.stderr:write("Connected as ", conn.jid, "\n");
8 if opts.interactive or opts.stdin then
9 local stdin = {
10 getfd = function () return 0; end;
11 dirty = function (self) return false; end;
12 settimeout = function () end;
13 send = function (_, d) return #d, 0; end;
14 close = function () end;
15 receive = function (_, patt)
16 local data = io.stdin:read(patt);
17 if opts.echo then
18 io.write(data, patt == "*l" and "\n" or "");
19 end
20 return data;
21 end
22 };
23 local function on_incoming(stdin, data)
24 conn:send(data);
25 if not opts.interactive then
26 conn:close();
27 end
28 end
29 stdin = require "net.server".wrapclient(stdin, "stdin", 0, {
30 onincoming = on_incoming, ondisconnect = function () end
31 }, "*l");
32 else
33 conn:send(table.concat(arg, " "));
34 conn:close();
35 end
36
37 end
38 return clix_connect(opts, on_connect);
39 end

mercurial