doc/example.lua

changeset 58
f9d025fde8dc
child 77
7af3e57501c2
equal deleted inserted replaced
57:8e8bac82e119 58:f9d025fde8dc
1 -- Change these:
2 local jid, password = "user@example.com", "secret";
3
4 -- This line squishes verse each time you run,
5 -- handy if you're hacking on Verse itself
6 --os.execute("squish --minify-level=none verse");
7
8 require "verse" -- Verse main library
9 require "verse.client" -- XMPP client library
10
11 c = verse.new()
12 c:add_plugin("sasl");
13 c:add_plugin("version");
14
15 -- Add some hooks for debugging
16 c:hook("opened", function () print("Stream opened!") end);
17 c:hook("closed", function () print("Stream closed!") end);
18 c:hook("stanza", function (stanza) print("Stanza:", stanza) end);
19
20 -- This one prints all received data
21 c:hook("incoming-raw", print, 1000);
22
23 -- Print a message after authentication
24 c:hook("authentication-success", function () print("Logged in!"); end);
25 c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end);
26
27 -- Print a message and exit when disconnected
28 c:hook("disconnected", function () print("Disconnected!"); os.exit(); end);
29
30 -- Now, actually start the connection:
31 c:connect_client(jid, password);
32
33 -- Catch binding-success which is (currently) how you know when a stream is ready
34 c:hook("binding-success", function ()
35 print("Stream ready!");
36 c.version:set{ name = "verse example client" };
37 c:query_version(c.jid, function (v) print("I am using "..(v.name or "<unknown>")); end);
38 end);
39
40 print("Starting loop...")
41 verse.loop()

mercurial