Added fd_add method for uloop lua binding.
authorXiongfei Guo <xfguo@credosemi.com>
Fri, 20 Jun 2014 10:31:18 +0000 (10:31 +0000)
committerJohn Crispin <blogic@openwrt.org>
Tue, 24 Jun 2014 13:30:30 +0000 (14:30 +0100)
commit79b56268b46ea2eaf7f79af7a64c57e2be37636a
tree2319f03ed7d0b045e998710454c17013325a8135
parent9565bf86ae48c47c744467e30b2219cf9cd70fbf
Added fd_add method for uloop lua binding.

Use uloop.fd_add like this:

    local socket = require "socket"

    udp = socket.udp()

    uloop.fd_add(
        udp, -- socket
        function( -- callback function
            ufd,    -- socket object when register the fd
            events  -- uloop events. eg. uloop.ULOOP_READ .
        )
            local words, msg_or_ip, port_or_nil = ufd:receivefrom()
            print('Recv UDP packet from '..msg_or_ip..':'..port_or_nil..' : '..words)
        end,
        uloop.ULOOP_READ -- event you want to listen
    )

The `examples/uloop-example.lua` show an example of this work.

Signed-off-by: Xiongfei(Alex) Guo <xfguo@credosemi.com>
examples/uloop-example.lua
lua/uloop.c