Advertisement
Guest User

MPD via LuaSocket

a guest
May 25th, 2010
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. local socket = require("socket")
  2.  
  3. foo = socket.protect(function(action)
  4. -- connect somewhere
  5. local c = socket.try(socket.connect("localhost", 6600))
  6. -- create a try function that closes 'c' on error
  7. local try = socket.newtry(function() c:close() end)
  8. -- do everything reassured c will be closed
  9. try(c:send(action.."\r\n"))
  10. local answer = try(c:receive())
  11. print(answer)
  12. c:close()
  13. end)
  14.  
  15. foo("stop")
  16. -- OR
  17. foo("play")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement