luvit/luv — pull request #96 by creationix (2014-12-01 21:09:50+00:00)
Title: Uv methods

Instead of using a global `uv_handle` metatable for all wrapped uv_handle_t subtypes, create a unique `uv_{type}` for each of the concrete uv handle types. Also add a new `__index` property to these new metatables so that uv handles can be called in method mode. All the uv functions that expect that particular type as the first arg are included in this list. Also the `uv_handle_t` methods are included for all types and the `uv_stream_t` methods are included for the 3 stream subtypes (tcp, tty, pipe). Where multiple types had the same function and were prefixed by the type name, the prefix is dropped in method form. Thus `uv.tcp_connect` is just `:connect` on an instance of `uv_tcp`.

This enables the following tcp echo server:

```lua
local server = uv.new_tcp()
server:bind("127.0.0.1", 0)
server:listen(1, function ()
local client = uv.new_tcp()
server:accept(client)

client:read_start(function (err, data)
assert(not err, err)
if data then
client:write(data)
else
client:read_stop()
client:close()
server:close()
end
end)
end)
```