-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.lua
More file actions
62 lines (51 loc) · 1.11 KB
/
example.lua
File metadata and controls
62 lines (51 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
local jua
local w
if require then
jua = require("jua")
w = require("w")
else
os.loadAPI("jua")
jua = _G.jua
os.loadAPI("w")
w = _G.w
end
w.init(jua)
local ws
local timePassed = 0
jua.on("terminate", function()
print("Terminated")
if ws then ws.close() end
jua.stop()
end)
jua.on("mouse_click", function(event, button, x, y)
print("Mouse Click at X: "..x.." Y: "..y)
end)
jua.go(function()
w.open({
success = function(url, handle)
ws = handle
print("Successfully connected.")
ws.send("Hello world!")
jua.setInterval(function()
timePassed = timePassed + 1
ws.send(timePassed.." seconds have passed.")
end, 1)
jua.setTimeout(function()
print("The program ran for 15 seconds. Exiting...")
ws.close()
jua.stop()
end, 15)
end,
failure = function(url)
print("Failed to connect.")
jua.stop()
end,
message = function(url, data)
print("Message: "..data)
end,
closed = function(url)
print("Connection closed")
jua.stop()
end
}, "ws://echo.websocket.org")
end)