Commit graph

12 commits

Author SHA1 Message Date
Felix Fietkau
663d7d4b88 lua: add gc/delete support for processes
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2016-01-15 21:26:43 +01:00
Felix Fietkau
a8d12b22e0 lua: create a common function for userdata with gc
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2016-01-15 21:19:47 +01:00
xfguo@credosemi.com
6e8e6aca1d lua/uloop: 'end' is the keyword of Lua, use 'cancel' replace it.
Signed-off-by: Xiongfei Guo <xfguo@credosemi.com>
2014-07-27 11:31:07 +02:00
Xiongfei Guo
39a8fae441 Fix bug of GC in fd and timeout objects for lua binding.
fd and timeout lua object has a __gc method in its metatable. After the object
is freed and the another new object use the same reference in __uloop_cb and
__uloop_fds, the new object will be freed by the old __gc of the old object
when garbag collecting.

Signed-off-by: Xiongfei(Alex) Guo <xfguo@credosemi.com>
2014-06-24 14:30:30 +01:00
Xiongfei Guo
3c92274bee Fix bug of unref resources in Lua binding; fd method delete -> cancel.
Signed-off-by: Xiongfei(Alex) Guo <xfguo@credosemi.com>
2014-06-24 14:30:30 +01:00
Xiongfei Guo
02ca593347 Support delete a fd event.
When you call the fd_add, it will return an object with `delete` method.
So you can delete that event if you want.

Signed-off-by: Xiongfei(Alex) Guo <xfguo@credosemi.com>
2014-06-24 14:30:30 +01:00
Xiongfei Guo
79b56268b4 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>
2014-06-24 14:30:30 +01:00
Xiongfei Guo
9565bf86ae Fix stack overflow bug of uloop lua binding.
The static variable `state` in `lua/uloop.c` should be clean after every callback.

Signed-off-by: Xiongfei(Alex) Guo <xfguo@credosemi.com>
2014-06-24 14:30:30 +01:00
Felix Fietkau
db38b74ac6 add declarations for lua{open,close}_uloop to avoid warnings 2012-10-22 20:03:36 +02:00
Felix Fietkau
5038992465 lua: use relative paths for includes instead of system-wide 2012-10-04 14:14:52 +02:00
John Crispin
6ba84c7623 rename proc_cb to ul_process_cb
Signed-off-by: John Crispin <blogic@openwrt.org>
2012-09-29 01:15:54 +02:00
Felix Fietkau
a81cb397ef add lua binding for uloop (written by John Crispin) 2012-09-27 13:41:02 +02:00