-
Notifications
You must be signed in to change notification settings - Fork 0
/
ping_pong.lua
52 lines (40 loc) · 1.61 KB
/
ping_pong.lua
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
package.path = '/usr/local/lib/SPRITE/?.lua;' .. package.path
local s = require 'scheduler'
--------------------------------------------------------------------------------
-- Set some script constants
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Initialize the tasks.
--------------------------------------------------------------------------------
-- Create task properties and set an initial priority.
tp = Task_properties.new()
priority = tp:MAX_USER_TASK_PRIO()
-- Create the scheduler.
SCHEDULER_PERIOD = s.HZ_to_period(1)
scheduler = s.create(tp, SCHEDULER_PERIOD, priority)
priority = priority - 1
-- Create the ping task.
ping = Ping.new("Ping")
s.set_task_properties(ping, tp, SCHEDULER_PERIOD, priority)
priority = priority - 1
-- Create the pong task.
pong = Pong.new("Pong")
s.set_task_properties(pong, tp, SCHEDULER_PERIOD * 3, priority)
priority = priority - 1
--------------------------------------------------------------------------------
-- Start up the tasks.
--------------------------------------------------------------------------------
-- Start everything up.
print "Starting tasks..."
scheduler:start()
pong:start()
ping:start()
-- Use debug to pause the script and let the tasks run.
print "Use control-D to cleanly terminate execution."
debug:debug()
--------------------------------------------------------------------------------
-- Terminate the tasks.
--------------------------------------------------------------------------------
print "...Exiting"
ping:stop()
scheduler:stop()