Skip to content

Commit 121ed6c

Browse files
committed
Cleaned up strings
1 parent aad6161 commit 121ed6c

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

scheduler.lua

+10-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ function dprintf(...)
2121
end
2222
printf("%s:%d:%s:%s %s", info.source, info.currentline, info.name, name, sprintf(...))
2323
end
24+
25+
-- Disable debug printing
26+
-- Comment this out to enable debug output
2427
dprintf = function(...)end
2528

2629
function _make_selector(me, who)
@@ -76,7 +79,7 @@ end
7679

7780
function say(f, ...)
7881
local me = me()
79-
printf("%s says %q", me.Name, sprintf(f, ...))
82+
printf("%s says '%s'", me.Name, sprintf(f, ...))
8083
end
8184

8285
function recv()
@@ -90,10 +93,10 @@ end
9093
function send(who, what)
9194
local me = me()
9295
local selector = _make_selector(me, who)
93-
dprintf("%s sending %q to %s", me.Name, what, who)
96+
dprintf("%s sending '%s' to %s", me.Name, what, who)
9497
for co, child in pairs(child_by_co) do
9598
if selector(child) then
96-
printf("%s tells %s: %q", me.Name, child.Name, what)
99+
printf("%s tells %s '%s'", me.Name, child.Name, what)
97100
table.insert(child.Msgs, {Src = me, Msg = what})
98101
end
99102
end
@@ -102,6 +105,7 @@ end
102105
function any(...)
103106
local waiters = {...}
104107
return function()
108+
dprintf("waiter %s", waiters)
105109
for i, waiter in ipairs(waiters) do
106110
local ready, resp = waiter()
107111
if ready then
@@ -126,7 +130,7 @@ function msg_from(who)
126130
dprintf("%s<%d> is waiting for %s", me.Name, #me.Msgs, tostring(who))
127131
for i, msg in ipairs(me.Msgs) do
128132
if selector(msg.Src) then
129-
printf("%s hears %s %q", me.Name, msg.Src.Name, msg.Msg)
133+
printf("%s hears %s '%s'", me.Name, msg.Src.Name, msg.Msg)
130134
table.remove(me.Msgs, i)
131135
return true, msg
132136
end
@@ -140,7 +144,9 @@ function minutes(m)
140144
end
141145

142146
function seconds(s)
147+
local me = me()
143148
return function()
149+
dprintf("%s<%d> is waiting for %s", me.Name, #me.Msgs, s)
144150
s = s - 1
145151
return s < 1, nil
146152
end

soldier.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
say("Soldier on duty!")
1+
say("I'm going to sleep")
22

33
msg = wait(msg_from("general"))
44

@@ -8,7 +8,7 @@ which, msg = wait(any(msg_from("general"), seconds(20)))
88

99
attacking = false
1010
if which == 1 then
11-
say("The general says %q", msg.Msg)
11+
say("The general says '%s'", msg.Msg)
1212
attacking = true
1313
else
1414
say("forever alone :.(")

0 commit comments

Comments
 (0)