Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
# Please note that the package source code is licensed under its own
# license.

CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
PROJECT(lua-ev C)
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)

# Basic configurations
SET(INSTALL_CMOD share/lua/cmod CACHE PATH "Directory to install Lua binary modules (configure lua via LUA_CPATH)")
# / configs

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")

# Find lua using PkgConfig
find_package(PkgConfig REQUIRED)
pkg_check_modules(LUA REQUIRED lua)
# / Find lua using PkgConfig

# Find libev
FIND_LIBRARY (LIBEV_LIBRARY NAMES ev)
FIND_PATH (LIBEV_INCLUDE_DIR ev.h
Expand All @@ -25,17 +30,15 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")
FIND_PACKAGE_HANDLE_STANDARD_ARGS(libev DEFAULT_MSG LIBEV_LIBRARY LIBEV_INCLUDE_DIR)
# / Find libarchive

# Find lua
FIND_PACKAGE(Lua5X REQUIRED)
# / Find lua

# Define how to build ev.so:
INCLUDE_DIRECTORIES(${LIBEV_INCLUDE_DIR} ${LUA_INCLUDE_DIR})
ADD_LIBRARY(cmod_ev MODULE
lua_ev.c
)
SET_TARGET_PROPERTIES(cmod_ev PROPERTIES PREFIX "")
SET_TARGET_PROPERTIES(cmod_ev PROPERTIES OUTPUT_NAME ev)
TARGET_INCLUDE_DIRECTORIES(cmod_ev PRIVATE ${LIBEV_INCLUDE_DIR} ${LUA_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(cmod_ev ${LUA_LIBRARIES} ${LIBEV_LIBRARY})
# / build ev.so

Expand Down
46 changes: 0 additions & 46 deletions cmake/Modules/FindLua5X.cmake

This file was deleted.

4 changes: 2 additions & 2 deletions lua_ev.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ LUALIB_API int luaopen_ev(lua_State *L) {
*
* [+2, -0, -]
*/
static int version(lua_State *L) {
int version(lua_State *L) {
lua_pushnumber(L, ev_version_major());
lua_pushnumber(L, ev_version_minor());
return 2;
Expand All @@ -141,7 +141,7 @@ static int version(lua_State *L) {
* Taken from lua.c out of the lua source distribution. Use this
* function when doing lua_pcall().
*/
static int traceback(lua_State *L) {
int traceback(lua_State *L) {
if ( !lua_isstring(L, 1) ) return 1;

lua_getglobal(L, "debug");
Expand Down
8 changes: 4 additions & 4 deletions lua_ev.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
/**
* Generic functions:
*/
static int version(lua_State *L);
static int traceback(lua_State *L);
int version(lua_State *L);
int traceback(lua_State *L);

/**
* Loop functions:
Expand Down Expand Up @@ -131,9 +131,9 @@ static void create_obj_registry(lua_State *L);
static int obj_count(lua_State *L);
static void* obj_new(lua_State* L, size_t size, const char* tname);
static int obj_newindex(lua_State *L);
static int obj_index(lua_State *L);
int obj_index(lua_State *L);

static int push_objs(lua_State* L, void** objs);
int push_objs(lua_State* L, void** objs);

/**
* Watcher functions:
Expand Down
4 changes: 2 additions & 2 deletions obj_lua_ev.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static int obj_newindex(lua_State *L) {
*
* [-0, +1, ?]
*/
static int obj_index(lua_State *L) {
int obj_index(lua_State *L) {
if ( lua_getmetatable(L, 1) ) {
lua_pushvalue(L, 2);
lua_gettable(L, -2);
Expand Down Expand Up @@ -139,7 +139,7 @@ static void register_obj(lua_State*L, int obj_i, void* obj) {
*
* [-0, +objs_len, m]
*/
static int push_objs(lua_State* L, void** objs) {
int push_objs(lua_State* L, void** objs) {
int obj_count = 0;
int registry_i;
void** cur;
Expand Down
11 changes: 3 additions & 8 deletions watcher_lua_ev.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,9 @@ static void* watcher_new(lua_State* L, size_t size, const char* lua_type) {
static void watcher_cb(struct ev_loop *loop, void *watcher, int revents) {
lua_State* L = ev_userdata(loop);
void* objs[3] = { loop, watcher, NULL };
int result;

lua_pushcfunction(L, traceback);

result = lua_checkstack(L, 5);
assert(result != 0 /* able to allocate enough space on lua stack */);
result = push_objs(L, objs);
assert(result == 2 /* pushed two objects on the lua stack */);
(void)objs;
assert(lua_checkstack(L, 5) != 0 /* able to allocate enough space on lua stack */);
assert(push_objs(L, objs) == 2 /* pushed two objects on the lua stack */);
assert(!lua_isnil(L, -2) /* the loop obj was resolved */);
assert(!lua_isnil(L, -1) /* the watcher obj was resolved */);

Expand Down