Skip to content

Instantly share code, notes, and snippets.

@ahappyforest
Created January 6, 2013 07:51
Show Gist options
  • Save ahappyforest/4465922 to your computer and use it in GitHub Desktop.
Save ahappyforest/4465922 to your computer and use it in GitHub Desktop.
local agent = require "agent"
a = agent.create(function (self)
self:listen {
login = function (self)
self:listen {
username = function(self , ...)
print("username", ...)
self:listen {
password = function(self, ...)
print("password", ...)
self:quit()
end
}
self:quit()
end ,
}
end,
ok = function (self)
self:quit()
end,
}
print "login ok"
local q = 0
self:listen {
chat = function (self, ...)
print("chat", ...)
end,
question = function (self , ...)
print("question", ...)
local answer = "answer" .. q
q = q+1
self:fork {
[answer] = function (self, ...)
print("answer", ...)
self:quit()
end
}
end,
}
end)
a:send("login")
a:send("username","alice")
a:send("username","bob")
a:send("password","xxx")
a:send("login")
a:send("username","bob")
a:send("password","yyy")
a:send("chat","foobar")
a:send("ok")
a:send("chat", "hello")
a:send("question","?0")
a:send("chat", "world")
a:send("question","?1")
a:send("answer0","!0")
a:send("answer1","!1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment