Commit graph

15 commits

Author SHA1 Message Date
Matthias Schiffer
1f019ceea1 Fix various memory management issues
Consistently handle allocation failures. Some functions are changed to
return bool or int instead of void to allow returning an error.

Also fix a buffer size miscalculation in lua/uloop and use _exit() instead
of exit() on errors after forking.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
2016-06-26 12:53:51 +02:00
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
Karl Palsson
682e071ef7 libubox: lua: use pkg-config built in module to search for alternatives
Different distributions have different names for the lua 5.1 package.
Use cmake's built in pkg-config support to search for the first one,
rather than running it explicitly and searching for a single version.

Signed-off-by: Karl Palsson <karlp@remake.is>
2015-11-22 13:17:07 +01:00
Yousong Zhou
c5d80836cd lua: do not hardcode /opt/local/include for Apple.
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2014-12-11 17:57:07 +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