Giter Site home page Giter Site logo

lua-ev's Introduction

lua-ev

Requirements

Loading the library

  • If you built the library as a loadable package
[local] ev = require 'ev'
  • If you compiled the package statically into your application, call the function luaopen_ev(L). It will create a table with the ev functions and leave it on the stack.

Choosing a backend:

Set the LIBEV_FLAGS= environment variable to choose a backend:

  1. select()
  2. poll()
  3. epoll()
  4. kqueue
  5. /dev/poll (not implemented)
  6. Solaris port

Please see the documentation for libev for more details.

WARNING:

If your program fork()s, then you will need to re-initialize your event loop(s) in the child process. You can do this re-initialization using the loop:fork() function.

NOTE:

If you are new to event loop programming, take a look at example.lua.

ev functions

major, minor = ev.version()

returns numeric ev version for the major and minor levels of the version dynamically linked in.

loop = ev.Loop.new()

Create a new non-default event loop. See ev.Loop object methods below.

loop = ev.Loop.default

The "default" event loop. See ev.Loop object methods below. Note that the default loop is "lazy loaded".

timer = ev.Timer.new(on_timeout, after_seconds [, repeat_seconds])

Create a new timer that will call the on_timeout function when the timer expires. The timer initially expires in after_seconds (floating point), then it will expire in repeat_seconds (floating point) over and over again (unless repeat_seconds is zero or is omitted in which case, this timer will only fire once).

The returned timer is an ev.Timer object. See below for the methods on this object.

NOTE: You must explicitly register the timer with an event loop in order for it to take effect.

The on_timeout function will be called with these arguments (return values are ignored):

on_timeout(loop, timer, revents)

The loop is the event loop for which the timer is registered, the timer is the ev.Timer object, and revents is ev.TIMEOUT.

See also ev_timer_init() C function.

sig = ev.Signal.new(on_signal, signal_number)

Create a new signal watcher that will call the on_signal function when the specified signal_number is delivered.

The returned sig is an ev.Signal object. See below for the methods on this object.

NOTE: You must explicitly register the sig with an event loop in order for it to take effect.

The on_signal function will be called with these arguments (return values are ignored):

on_signal(loop, sig, revents)

The loop is the event loop for which the io object is registered, the sig parameter is the ev.Signal object, and revents is ev.SIGNAL.

See also ev_signal_init() C function.

io = ev.IO.new(on_io, file_descriptor, revents)

Create a new io watcher that will call the on_io function when the specified file_descriptor is available for read and/or write depending on the revents. The revents parameter must be either ev.READ, ev.WRITE, or the bitwise or of ev.READ and ev.WRITE (use bitlib to do bitwise or).

The returned io is an ev.IO object. See below for the methods on this object.

NOTE: You must explicitly register the io with an event loop in order for it to take effect.

The on_io function will be called with these arguments (return values are ignored):

on_io(loop, io, revents)

The loop is the event loop for which the io object is registered, the io parameter is the ev.IO object, and revents is a bit set consisting of ev.READ and/or ev.WRITE and/or ev.TIMEOUT depending on which event triggered this callback. Of course ev.TIMEOUT won't be in that set since this is the io watcher.

See also ev_io_init() C function.

idle = ev.Idle.new(on_idle)

Create a new io watcher that will call the on_idle function whenever there is nothing else to do. This means that the loop will never block while an idle watcher is started.

The returned io is an ev.Idle object. See below for the methods on this object.

NOTE: You must explicitly register the idle with an event loop in order for it to take effect.

The on_idle function will be called with these arguments (return values are ignored):

on_idle(loop, idle, revents)

The loop is the event loop for which the idle object is registered, the idle parameter is the ev.Idle object, and revents is ev.IDLE.

See also ev_idle_init() C function.

async = ev.Async.new(on_async)

Create a new async watcher that will call the on_async function whenever an application calls ev_async_send() from another context (this can be another thread or some other context which does not control the loop this watcher lives on)

The returned async is an ev.Async object. See below for the methods on this object.

NOTE: You must explicitly register the async with an event loop in order for it to take effect.

The on_async function will be called with these arguments (return values are ignored):

For a LuaJIT/FFI helper about the use of ev_async_send() from another thread, see contrib/ev-async.lua.

on_async(loop, idle, revents)

The loop is the event loop for which the idle object is registered, the idle parameter is the ev.Idle object, and revents is ev.IDLE.

See also ev_idle_init() C function.

child = ev.Child.new(on_child, pid, trace)

Create a new child watcher that will call the on_child function whenever SIGCHLD for registered pid is delivered.

When pid is set to 0 the watcher will fire for any pid.

When trace is false the watcher will be activated when the process terminates. If it's true - it will additionally be activated when the process is stopped or continued.

The returned child is an ev.Child object. See below for the methods on this object.

NOTE: You must explicitly register the idle with an event loop in order for it to take effect.

The on_child function will be called with these arguments (return values are ignored):

on_child(loop, child, revents)

The loop is the event loop for which the idle object is registered, the child parameter is the ev.Child object, and revents is ev.CHILD.

See also ev_child_init() C function.

stat = ev.Stat.new(on_stat, path [, interval])

Configures the watcher to wait for status changes of the given "path". The "interval" is a hint on how quickly a change is expected to be detected and may normally be left out to let libev choose a suitable value.

The returned stat is an ev.Stat object. See below for the methods on this object.

NOTE: You must explicitly register the stat with an event loop in order for it to take effect.

The on_stat function will be called with these arguments (return values are ignored):

on_stat(loop, stat, revents)

The loop is the event loop for which the idle object is registered, the stat parameter is the ev.Stat object, and revents is ev.STAT.

See also ev_stat_init() C function.

ev.READ (constant)

If this bit is set, the io watcher is ready to read. See also EV_READ C definition.

ev.WRITE (constant)

If this bit is set, the io watcher is ready to write. See also EV_WRITE C definition.

ev.TIMEOUT (constant)

If this bit is set, the watcher was triggered by a timeout. See also EV_TIMEOUT C definition.

ev.SIGNAL (constant)

If this bit is set, the watcher was triggered by a signal. See also EV_SIGNAL C definition.

ev.ASYNC (constant)

If this bit is set, the watcher has been asynchronously notified. See also EV_ASYNC C definition.

ev.CHILD (constant)

If this bit is set, the watcher was triggered by a child signal. See also EV_CHILD C definition.

ev.STAT (constant)

If this bit is set, the watcher was triggered by a change in attributes of the file system path. See also EV_STAT C definition.

ev.Loop object methods

loop:fork()

You must call this function in the child process after fork(2) system call and before the next iteration of the event loop.

loop:loop()

Run the event loop! Returns when there are no more watchers registered with the event loop. See special note below about calling ev_loop() C API.

See also ev_loop() C function.

bool = loop:is_default()

Returns true if the referenced loop object is the default event loop.

See also ev_is_default_loop() C function.

num = loop:iteration()

Returns the number of loop iterations. Note that this function used to be called loop:count().

See also ev_iterations() C function.

num = loop:depth() [libev >= 3.7]

Returns the number of times loop:loop() was entered minus the number of times loop:loop() was exited, in other words, the recursion depth.

This method is available only if lua-ev was linked with libev 3.7 and higher.

See also ev_depth() C function.

epochs = loop:now()

Returns the non-integer epoch seconds time at which the current iteration of the event loop woke up.

See also ev_now() C function.

epochs = loop:update_now()

Updates the current time returned by loop.now(), and returns that timestamp.

See also ev_now_update() C function.

loop:unloop()

Process all outstanding events in the event loop, but do not make another iteration of the event loop.

See also ev_unloop() C function.

backend_id = loop:backend()

Returns the identifier of the current backend which is being used by this event loop. See the libev documentation for what each number means:

http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#FUNCTIONS_CONTROLLING_THE_EVENT_LOOP

object methods common to all watcher types

bool = watcher:is_active()

Returns true if the watcher is active (has been start()ed, but not stop()ed).

See also ev_is_active() C function.

bool = watcher:is_pending()

Returns true if the watcher is pending (it has outstanding events but its callback has not yet been invoked).

See also ev_is_pending() C function.

revents = watcher:clear_pending()

If the watcher is pending, return the revents of the pending event, otherwise returns zero. If the event was pending, the pending flag is cleared (and therefore this watcher event will not trigger the events callback).

See also ev_clear_pending() C function.

old_priority = watcher:priority([new_priority])

Get access to the priority of this watcher, optionally setting a new priority. The priority should be a small integer between ev.MINPRI and ev.MAXPRI. The default is 0.

See also the ev_priority() and ev_set_priority() C functions.

old_callback = watcher:callback([new_callback])

Get access to the callback function associated with this watcher, optionally setting a new callback function.

ev.Timer object methods

timer:start(loop [, is_daemon])

Start the timer in the specified event loop. Optionally make this watcher a "daemon" watcher which means that the event loop will terminate even if this watcher has not triggered.

See also ev_timer_start() C function (document as ev_TYPE_start()).

timer:stop(loop)

Unregister this timer from the specified event loop. Ensures that the watcher is neither active nor pending.

See also ev_timer_stop() C function (document as ev_TYPE_stop()).

timer:again(loop [, seconds])

Reset the timer so that it doesn't trigger again in the specified loop until the specified number of seconds from now have elapsed. If seconds is not specified, uses the repeat_seconds specified when the timer was created.

See also ev_timer_again() C function.

ev.IO object methods

io:start(loop [, is_daemon])

Start the io in the specified event loop. Optionally make this watcher a "daemon" watcher which means that the event loop will terminate even if this watcher has not triggered.

See also ev_io_start() C function (document as ev_TYPE_start()).

io:stop(loop)

Unregister this io from the specified event loop. Ensures that the watcher is neither active nor pending.

See also ev_io_stop() C function (document as ev_TYPE_stop()).

fd = io:getfd()

Returns the file descriptor associated with the IO object.

ev.Idle object methods

idle:start(loop [, is_daemon])

Start the idle watcher in the specified event loop. Optionally make this watcher a "daemon" watcher which means that the event loop will terminate even if this watcher has not triggered.

See also ev_idle_start() C function (document as ev_TYPE_start()).

idle:stop(loop)

Unregister this idle watcher from the specified event loop. Ensures that the watcher is neither active nor pending.

See also ev_io_stop() C function (document as ev_TYPE_stop()).

ev.Async object methods

async:start(loop [, is_daemon])

Start the async watcher in the specified event loop. Optionally make this watcher a "daemon" watcher which means that the event loop will terminate even if this watcher has not triggered.

See also ev_async_start() C function (document as ev_TYPE_start()).

async:stop(loop)

Unregister this async watcher from the specified event loop. Ensures that the watcher is neither active nor pending.

See also ev_async_stop() C function (document as ev_TYPE_stop()).

async:send(loop)

Sends/signals/activates the given "ev_async" watcher, that is, feeds an "EV_ASYNC" event on the watcher into the event loop, and instantly returns.

See also ev_async_send() C function.

ev.Child object methods

child:start(loop [, is_daemon])

Start the child watcher in the specified event loop. Optionally make this watcher a "daemon" watcher which means that the event loop will terminate even if this watcher has not triggered.

See also ev_child_start() C function (document as ev_TYPE_start()).

child:stop(loop)

Unregister this child watcher from the specified event loop. Ensures that the watcher is neither active nor pending.

See also ev_child_stop() C function (document as ev_TYPE_stop()).

child:getpid()

Return the process id this watcher watches out for, or 0, meaning any process id.

child:getrpid()

Return the process id that detected a status change.

child:getstatus()

Returns the process exit/trace status caused by "rpid" (see your systems "waitpid" and "sys/wait.h" for details).

It returns the table with the following fields:

  • exited: true if status was returned for a child process that terminated normally;
  • stopped: true if status was returned for a child process that is currently stopped;
  • signaled: true if status was returned for a child process that terminated due to receipt of a signal that was not caught;
  • exit_status: (only if exited == true) the low-order 8 bits of the status argument that the child process passed to _exit() or exit(), or the value the child process returned from main();
  • stop_signal`: (only if stopped == true) the number of the signal that caused the child process to stop;
  • term_signal: (only if signaled == true) the number of the signal that caused the termination of the child process.

ev.Stat object methods

stat:start(loop [, is_daemon])

Start the stat watcher in the specified event loop. Optionally make this watcher a "daemon" watcher which means that the event loop will terminate even if this watcher has not triggered.

See also ev_stat_start() C function (document as ev_TYPE_start()).

stat:stop(loop)

Unregister this stat watcher from the specified event loop. Ensures that the watcher is neither active nor pending.

See also ev_stat_stop() C function (document as ev_TYPE_stop()).

stat:getdata()

Returns a table with the following fields:

    • path: the file system path that is being watched;
    • interval: the specified interval;
    • attr: the most-recently detected attributes of the file in a form
  • of table with the following fields: dev, ino, mode, nlink, uid, gid,
  • rdev, size, atime, mtime, ctime corresponding to struct stat members
  • (st_dev, st_ino, etc.);
    • prev: the previous attributes of the file with the same fields as
  • attr fields.

EXCEPTION HANDLING NOTE

If there is an exception when calling a watcher callback, the error will be printed to stderr. In the future, it would be cool if there was a linked list of error handlers, and that if a callback registers another callback, this linked list of error handlers would be inherited so that exception handling can be done more easily. To do this, we just need to add a method for adding an error handler for the current callback context, and keep calling the error handlers in the linked list until an error handler actually handles the exception. If the error handling stack unwinds, we will probably just resort to printing to stderr.

CALLING ev_loop() C API DIRECTLY:

If you want to call the ev_loop() C API directly, then you MUST set the loop userdata field to the lua_State in which you want all callbacks to be ran in. In the past, the lua_State was stored as a thread local which was set when loop:loop() lua function is called, but this made lua-ev dependent upon pthreads and forced ev_loop() to only be called from lua. Next, I removed the pthreads dependency and stored the lua_State in which the callback was registered. This doesn't bode well when working with coroutines as it means that loop:loop() may call back into a coroutine that is long gone.

The current implementation relies on libev 3.7's ability to set a userdata field associated with an event loop, and the loop:loop() implementation simply sets the userdata field for the duration of loop:loop(). This does mean that if you want to call ev_loop() from C then you either need to be sure that no lua watchers are registered with that loop, or you need to set the userdata field to the lua_State* in which the callbacks should be ran.

TODO

  • Add support for other watcher types (periodic, embed, etc).

MIT License

lua-ev's People

Contributors

agladysh avatar bdowning avatar brimworks avatar daurnimator avatar imagicthecat avatar klimkiewicz avatar lipp avatar nathan-miller-actigraph avatar piernov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lua-ev's Issues

Async watchers for multi-threading.

Hi,

Currently the async watcher API doesn't seem to handle the use case of multi-threading synchronization (waking up the event loop from a different thread). Could it be implemented with the Lua C API in a flexible way to interface with threading libraries ? (open question)

Make package building with Lua 5.4

There are versions of Lua hard-coded into cmake/Modules/FindLua5X.cmake and Lua 5.4 is missing. Why don’t you use standard cmake/Modules/FindLua.cmake, by the way?

Anyway, this patch works around this problem.

Can't watch directories

You can't seem to watch directories:

ev = require"ev"
do -- Add getfd function to file namespace
    local ok , posix = pcall ( require , "posix" )
    if ok then
        getmetatable ( io.stdin ).__index.getfd = posix.fileno
    else
        error ( "Unable to watch file descriptors" )
    end
end
loop=ev.Loop.new()
fd=io.open(".")
io = ev.IO.new ( print , fd:getfd() , ev.READ +ev.WRITE )
io:start(loop)
loop:loop()
print("Should never get here")

Help with build and dependencies

Hello,

I am not conversant with CMake, also if I have to include this project into the build system that we already have, then I have to write a waf script (wscript) for lua-ev. May I request to please add a simple Unix Makefile, or give me the dependency and build steps, so that I can integrate into our build system.

Thanks.

Windows VS2010 build

Trying to compile with VS2010:

1>------ Build started: Project: ZERO_CHECK, Configuration: Debug x64 ------
1>Build started 10/23/2011 5:11:24 PM.
1>InitializeBuildStatus:
1> Creating "x64\Debug\ZERO_CHECK\ZERO_CHECK.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>CustomBuild:
1> Checking Build System
1> CMake does not need to re-run because U:/Programming/lua-ev/CMakeFiles/generate.stamp is up-to-date.
1>FinalizeBuildStatus:
1> Deleting file "x64\Debug\ZERO_CHECK\ZERO_CHECK.unsuccessfulbuild".
1> Touching "x64\Debug\ZERO_CHECK\ZERO_CHECK.lastbuildstate".
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:00.59
2>------ Build started: Project: cmod_ev, Configuration: Debug x64 ------
2>Build started 10/23/2011 5:11:24 PM.
2>InitializeBuildStatus:
2> Creating "cmod_ev.dir\Debug\cmod_ev.unsuccessfulbuild" because "AlwaysCreate" was specified.
2>CustomBuild:
2> Building Custom Rule U:/Programming/lua-ev/CMakeLists.txt
2> CMake does not need to re-run because U:\Programming\lua-ev\CMakeFiles\generate.stamp is up-to-date.
2>ClCompile:
2> lua_ev.c
2>u:\programming\lua-ev\loop_lua_ev.c(97): warning C4244: 'initializing' : conversion from 'lua_Integer' to 'unsigned int', possible loss of data
2>u:\programming\lua-ev\child_lua_ev.c(1): fatal error C1083: Cannot open include file: 'sys/wait.h': No such file or directory
2>
2>Build FAILED.
2>
2>Time Elapsed 00:00:01.12
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Build lua-ev on Windows

Hello! Could someone explain me how to build lua-ev on windows?
I have tried to build libev manually but it failed. I have tried to find compliled library on the internet but it failed again.

luarocks config.lua

rocks_trees = {
    { name = [[user]],
         root    = home..[[/luarocks]],
    },
    { name = [[system]],
         root    = [[C:\Program Files (x86)\LuaRocks\systree]],
    },
}
variables = {
    MSVCRT = 'MSVCR80',
    LUALIB = [[lib\lua5.1.lib]],
    CFLAGS = '"-IC:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\include" "-IC:\\MinGW\\building\\libev-4.20"',
    CMAKE = '"C:\\Program Files (x86)\\CMake\\bin\\cmake.exe"'
}
verbose = true   -- set to 'true' to enable verbose output

luarocks install lua-ev (verbose=false)

C:\>luarocksw install lua-ev
executing: luarocks install lua-ev
Installing https://luarocks.org/lua-ev-v1.4-1.rockspec...
Using https://luarocks.org/lua-ev-v1.4-1.rockspec... switching to 'build' mode
Cloning into 'lua-ev'...
remote: Counting objects: 35, done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 35 (delta 5), reused 17 (delta 0), pack-reused 0 eceiving objects:  85% (30/35)
Receiving objects: 100% (35/35), 30.06 KiB, done.
Resolving deltas: 100% (5/5), done.
Note: checking out '458165bdfe0c6eadc788813925f11a0e6a823845'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

cl "-IC:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include" "-IC:\MinGW\building\libev-4.20" -c -Folua_ev.obj -IC:/Program Files (x86)/Lua/5.1/include/ lua_ev.c
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.21005.1 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

lua_ev.c
C:\MinGW\building\libev-4.20\ev.h(931) : warning C4005: 'SIGABRT' : macro redefinition
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\signal.h(43) : see previous definition of 'SIGABRT'
C:\MinGW\building\libev-4.20\ev.h(996) : warning C4005: 'NSIG' : macro redefinition
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\signal.h(32) : see previous definition of 'NSIG'
link -dll -def:ev.def -out:ev.dll C:/Program Files (x86)/Lua/5.1/lib\lua5.1.lib lua_ev.obj ev.lib
Microsoft (R) Incremental Linker Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

LINK : fatal error LNK1181: cannot open input file 'ev.lib'

Error: Build error: Failed compiling module ev.dll
Press any key to continue . . .

luarocks not install lua-ev. please teach me lua-ev install.

Sorry Please teach me How to install official .

Enviroment Scientific Linux 6.3

yum install libev libev-devel already install

I tried luarocks install ...

luarocks install lua-ev
Installing http://luarocks.org/repositories/rocks/lua-ev-v1.3-1.src.rock...
Using http://luarocks.org/repositories/rocks/lua-ev-v1.3-1.src.rock... switching to 'build' mode
Archive:  /tmp/luarocks_luarocks-rock-lua-ev-v1.3-1-9367/lua-ev-v1.3-1.src.rock
  inflating: lua-ev-v1.3-1.rockspec  
  inflating: lua-ev-v1.3.tar.gz      

Error: Could not find expected file libev.so for LIBEV -- you may have to install LIBEV in your system and/or pass LIBEV_DIR or LIBEV_LIBDIR to the luarocks command. Example: luarocks install lua-ev LIBEV_DIR=/usr/local
locate libev.so
/usr/lib64/libev.so
/usr/lib64/libev.so.4
/usr/lib64/libev.so.4.0.0

locate ev.h
/usr/include/libev/ev.h
  -
  - 
luarocks install lua-ev LIBEV_LIBDIR=/usr/lib64/ LIBEV_DIR=/usr/include/libev/ev.h 
Installing http://luarocks.org/repositories/rocks/lua-ev-v1.3-1.src.rock...
Using http://luarocks.org/repositories/rocks/lua-ev-v1.3-1.src.rock... switching to 'build' mode
Archive:  /tmp/luarocks_luarocks-rock-lua-ev-v1.3-1-1027/lua-ev-v1.3-1.src.rock
  inflating: lua-ev-v1.3-1.rockspec  
  inflating: lua-ev-v1.3.tar.gz      

Error: Could not find expected file ev.h for LIBEV -- you may have to install LIBEV in your system and/or pass LIBEV_DIR or LIBEV_INCDIR to the luarocks command. Example: luarocks install lua-ev LIBEV_DIR=/usr/local

so git clone lua-ev and cmake

cmake28 . && make
-- Could NOT find libev (missing:  LIBEV_INCLUDE_DIR) 
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LIBEV_INCLUDE_DIR
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev
   used as include directory in directory /root/lua-ev

-- Configuring incomplete, errors occurred!

my change CMakeLists.txt .

--- lua-ev_org/CMakeLists.txt   2012-09-28 01:41:52.271586069 +0900
+++ lua-ev/CMakeLists.txt       2012-09-28 02:41:46.929629477 +0900
@@ -15,9 +15,14 @@
 # / configs

 # Find libev
-  FIND_LIBRARY (LIBEV_LIBRARY NAMES ev)
+  FIND_LIBRARY (LIBEV_LIBRARY NAMES ev
+    PATH_SUFFIXES libev
+    PATHS
+      /usr/lib64)
   FIND_PATH (LIBEV_INCLUDE_DIR ev.h
     PATH_SUFFIXES include/ev include
+    PATHS
+      /usr/include/libev
     ) # Find header
   INCLUDE(FindPackageHandleStandardArgs)
   FIND_PACKAGE_HANDLE_STANDARD_ARGS(libev  DEFAULT_MSG  LIBEV_LIBRARY LIBEV_INCLUDE_DIR)

try cmake complete ..

#cmake .
-- Found libev: /usr/lib64/libev.so  
-- Configuring done
-- Generating done
-- Build files have been written to: /root/lua-ev
# make
Scanning dependencies of target cmod_ev
[100%] Building C object CMakeFiles/cmod_ev.dir/lua_ev.c.o
Linking C shared module ev.so
[100%] Built target cmod_ev

please teache me official install ...

do not pcall() the associated watcher callbacks

Hoy!

I'm not sure it is a good idea to impose a pcall() on all callbacks. The user could easily wrap their callbacks in a pcall()'ing function on their own. It would mean less "liability" for lua-ev while placing this responsibility on the user -- where it belongs, imo. Even if an error were not handled and the loop were "jumped out of" memory would still be cleaned up on the termination of the script..

Yes? :-)

Not building in Mac

I'm not a real programmer, so this might be really easy, but I'm getting a pretty basic error when trying to build on a Mac.

~/src/lua-ev[master*]% make
[100%] Building C object CMakeFiles/cmod_ev.dir/lua_ev.c.o
In file included from /Users/andrew/src/lua-ev/lua_ev.c:6:
/Users/andrew/src/lua-ev/lua_ev.h:147: error: expected declaration specifiers or ‘...’ before ‘luaL_reg’
In file included from /Users/andrew/src/lua-ev/lua_ev.c:19:
/Users/andrew/src/lua-ev/loop_lua_ev.c: In function ‘create_loop_mt’:
/Users/andrew/src/lua-ev/loop_lua_ev.c:28: error: nested functions are disabled, use -fnested-functions to re-enable
/Users/andrew/src/lua-ev/loop_lua_ev.c:28: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘methods’
/Users/andrew/src/lua-ev/loop_lua_ev.c:28: error: ‘methods’ undeclared (first use in this function)
/Users/andrew/src/lua-ev/loop_lua_ev.c:28: error: (Each undeclared identifier is reported only once
/Users/andrew/src/lua-ev/loop_lua_ev.c:28: error: for each function it appears in.)
/Users/andrew/src/lua-ev/loop_lua_ev.c:28: error: expected expression before ‘]’ token
In file included from /Users/andrew/src/lua-ev/lua_ev.c:20:
/Users/andrew/src/lua-ev/watcher_lua_ev.c: At top level:
/Users/andrew/src/lua-ev/watcher_lua_ev.c:11: error: expected declaration specifiers or ‘...’ before ‘luaL_reg’
/Users/andrew/src/lua-ev/watcher_lua_ev.c: In function ‘add_watcher_mt’:
/Users/andrew/src/lua-ev/watcher_lua_ev.c:13: error: nested functions are disabled, use -fnested-functions to re-enable
/Users/andrew/src/lua-ev/watcher_lua_ev.c:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘common_methods’
/Users/andrew/src/lua-ev/watcher_lua_ev.c:13: error: ‘common_methods’ undeclared (first use in this function)
/Users/andrew/src/lua-ev/watcher_lua_ev.c:13: error: expected expression before ‘]’ token
/Users/andrew/src/lua-ev/watcher_lua_ev.c:32: error: ‘methods’ undeclared (first use in this function)
In file included from /Users/andrew/src/lua-ev/lua_ev.c:21:
/Users/andrew/src/lua-ev/io_lua_ev.c: In function ‘create_io_mt’:
/Users/andrew/src/lua-ev/io_lua_ev.c:25: error: nested functions are disabled, use -fnested-functions to re-enable
/Users/andrew/src/lua-ev/io_lua_ev.c:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘methods’
/Users/andrew/src/lua-ev/io_lua_ev.c:25: error: ‘methods’ undeclared (first use in this function)
/Users/andrew/src/lua-ev/io_lua_ev.c:25: error: expected expression before ‘]’ token
/Users/andrew/src/lua-ev/io_lua_ev.c:31: error: too many arguments to function ‘add_watcher_mt’
In file included from /Users/andrew/src/lua-ev/lua_ev.c:22:
/Users/andrew/src/lua-ev/timer_lua_ev.c: In function ‘create_timer_mt’:
/Users/andrew/src/lua-ev/timer_lua_ev.c:25: error: nested functions are disabled, use -fnested-functions to re-enable
/Users/andrew/src/lua-ev/timer_lua_ev.c:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘methods’
/Users/andrew/src/lua-ev/timer_lua_ev.c:25: error: ‘methods’ undeclared (first use in this function)
/Users/andrew/src/lua-ev/timer_lua_ev.c:25: error: expected expression before ‘]’ token
/Users/andrew/src/lua-ev/timer_lua_ev.c:32: error: too many arguments to function ‘add_watcher_mt’
In file included from /Users/andrew/src/lua-ev/lua_ev.c:23:
/Users/andrew/src/lua-ev/signal_lua_ev.c: In function ‘create_signal_mt’:
/Users/andrew/src/lua-ev/signal_lua_ev.c:25: error: nested functions are disabled, use -fnested-functions to re-enable
/Users/andrew/src/lua-ev/signal_lua_ev.c:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘methods’
/Users/andrew/src/lua-ev/signal_lua_ev.c:25: error: ‘methods’ undeclared (first use in this function)
/Users/andrew/src/lua-ev/signal_lua_ev.c:25: error: expected expression before ‘]’ token
/Users/andrew/src/lua-ev/signal_lua_ev.c:30: error: too many arguments to function ‘add_watcher_mt’
In file included from /Users/andrew/src/lua-ev/lua_ev.c:24:
/Users/andrew/src/lua-ev/idle_lua_ev.c: In function ‘create_idle_mt’:
/Users/andrew/src/lua-ev/idle_lua_ev.c:25: error: nested functions are disabled, use -fnested-functions to re-enable
/Users/andrew/src/lua-ev/idle_lua_ev.c:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘methods’
/Users/andrew/src/lua-ev/idle_lua_ev.c:25: error: ‘methods’ undeclared (first use in this function)
/Users/andrew/src/lua-ev/idle_lua_ev.c:25: error: expected expression before ‘]’ token
/Users/andrew/src/lua-ev/idle_lua_ev.c:30: error: too many arguments to function ‘add_watcher_mt’
In file included from /Users/andrew/src/lua-ev/lua_ev.c:25:
/Users/andrew/src/lua-ev/child_lua_ev.c: In function ‘create_child_mt’:
/Users/andrew/src/lua-ev/child_lua_ev.c:30: error: nested functions are disabled, use -fnested-functions to re-enable
/Users/andrew/src/lua-ev/child_lua_ev.c:30: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘methods’
/Users/andrew/src/lua-ev/child_lua_ev.c:30: error: ‘methods’ undeclared (first use in this function)
/Users/andrew/src/lua-ev/child_lua_ev.c:30: error: expected expression before ‘]’ token
/Users/andrew/src/lua-ev/child_lua_ev.c:38: error: too many arguments to function ‘add_watcher_mt’
In file included from /Users/andrew/src/lua-ev/lua_ev.c:26:
/Users/andrew/src/lua-ev/stat_lua_ev.c: In function ‘create_stat_mt’:
/Users/andrew/src/lua-ev/stat_lua_ev.c:25: error: nested functions are disabled, use -fnested-functions to re-enable
/Users/andrew/src/lua-ev/stat_lua_ev.c:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘methods’
/Users/andrew/src/lua-ev/stat_lua_ev.c:25: error: ‘methods’ undeclared (first use in this function)
/Users/andrew/src/lua-ev/stat_lua_ev.c:25: error: expected expression before ‘]’ token
/Users/andrew/src/lua-ev/stat_lua_ev.c:31: error: too many arguments to function ‘add_watcher_mt’
/Users/andrew/src/lua-ev/lua_ev.c: At top level:
/Users/andrew/src/lua-ev/lua_ev.c:28: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘R’
/Users/andrew/src/lua-ev/lua_ev.c: In function ‘save_traceback’:
/Users/andrew/src/lua-ev/lua_ev.c:43: error: ‘LUA_GLOBALSINDEX’ undeclared (first use in this function)
/Users/andrew/src/lua-ev/lua_ev.c: In function ‘luaopen_ev’:
/Users/andrew/src/lua-ev/lua_ev.c:68: error: ‘R’ undeclared (first use in this function)
/Users/andrew/src/lua-ev/lua_ev.c: In function ‘traceback’:
/Users/andrew/src/lua-ev/lua_ev.c:149: error: ‘LUA_GLOBALSINDEX’ undeclared (first use in this function)
make[2]: *** [CMakeFiles/cmod_ev.dir/lua_ev.c.o] Error 1
make[1]: *** [CMakeFiles/cmod_ev.dir/all] Error 2
make: *** [all] Error 2

I have done a bunch of (probably wrong-headed and irrelevant) things to get around it, but I'm lost. It seems like it isn't valid C code. Enabling in-line functions did nothing for me. Using gcc-4.2 did nothing.

Any help would be appreciated. Thanks!

Install issues on OSX 10.13.3

$ CC=clang CXX=clang++ sudo -H luarocks install lua-ev
Installing https://luarocks.org/lua-ev-v1.4-1.rockspec
Cloning into 'lua-ev'...
remote: Counting objects: 35, done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 35 (delta 5), reused 18 (delta 0), pack-reused 0
Receiving objects: 100% (35/35), 30.13 KiB | 186.00 KiB/s, done.
Resolving deltas: 100% (5/5), done.
Note: checking out '458165bdfe0c6eadc788813925f11a0e6a823845'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

env MACOSX_DEPLOYMENT_TARGET=10.8 /usr/bin/clang -O2 -fPIC -I/opt/local/include -c lua_ev.c -o lua_ev.o
In file included from lua_ev.c:13:
./watcher_lua_ev.c:222:39: warning: implicit declaration of function 'luaL_checkint' is invalid in C99 [-Wimplicit-function-declaration]
    if ( has_pri ) ev_set_priority(w, luaL_checkint(L, 2));
                                      ^
In file included from lua_ev.c:19:
./stat_lua_ev.c:50:28: warning: implicit declaration of function 'luaL_optint' is invalid in C99 [-Wimplicit-function-declaration]
    ev_tstamp   interval = luaL_optint(L, 3, 0);
                           ^
2 warnings generated.
env MACOSX_DEPLOYMENT_TARGET=10.8 /usr/bin/clang -bundle -undefined dynamic_lookup -all_load -o ev.so -L/opt/local/lib lua_ev.o -lev
lua-ev v1.4-1 is now installed in /opt/local/share/luarocks (license: MIT/X11)

Lua 5.2 Support

I was wondering if you have any plans to eventually update your library to support Lua 5.2? Right now I'm using Lua 5.1 but would like to understand if 5.2 support is on your road map for the future. My experiences with your binding to libev have been very positive and I look forward to its future development.

Thanks . . .

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.