richardhundt / ray

Lua C API libuv bindings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NAME

ray - simple, coroutine friendly libuv bindings for Lua

DESCRIPTION

Ray provides:

  • TCP and UDP sockets
  • filesystem operations
  • timers

Oh, and it schedules coroutines instead of using callbacks.

Example

TCP echo client:

local ray = require('ray')
ray.fiber(function()
   local server = ray.tcp()
   server:bind('127.0.0.1', 8080)
   server:listen(128)
   while true do
      local client = server:accept()
      local fib = ray.fiber(function()
         while true do
            local data = client:read()
            if data then
               client:write("you said: "..data)
            else
               client:close()
               break
            end
         end
      end)
   end
end)

ray.run()

About

Lua C API libuv bindings


Languages

Language:C 90.5%Language:Objective-C 6.8%Language:Lua 2.7%