From 7eb84245607020b20fcf83404a7e4e93fc0a3f89 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 6 Dec 2009 01:10:59 +0000 Subject: Add base:loopexit() method --- src/luaevent.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/luaevent.c') diff --git a/src/luaevent.c b/src/luaevent.c index c9b5430..71188a6 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -89,9 +89,18 @@ static int luaevent_loop(lua_State* L) { return 1; } +static int luaevent_loopexit(lua_State*L) { + le_base *base = event_base_get(L, 1); + struct timeval tv = { 0, 10 }; + int ret = event_base_loopexit(base->base, &tv); + lua_pushinteger(L, ret); + return 1; +} + static luaL_Reg base_funcs[] = { { "addevent", luaevent_addevent }, { "loop", luaevent_loop }, + { "loopexit", luaevent_loopexit }, { NULL, NULL } }; -- cgit v1.2.3 From b797f511efc3843cf32d62f907f1cfa08fca3828 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 7 Dec 2009 21:36:31 +0000 Subject: base:loopexit(): Support for specifying the timeout before exit --- src/luaevent.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/luaevent.c') diff --git a/src/luaevent.c b/src/luaevent.c index 71188a6..550a386 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -91,7 +91,9 @@ static int luaevent_loop(lua_State* L) { static int luaevent_loopexit(lua_State*L) { le_base *base = event_base_get(L, 1); - struct timeval tv = { 0, 10 }; + struct timeval tv = { 0, 0 }; + if(lua_gettop(L) >= 2) /* Optional timeout before exiting the loop */ + load_timeval(luaL_checknumber(L, 2), &tv); int ret = event_base_loopexit(base->base, &tv); lua_pushinteger(L, ret); return 1; -- cgit v1.2.3 From bfd0058b760fb75ae466aa9049e9428645363a65 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 7 Dec 2009 21:44:00 +0000 Subject: Add base:method() to return string identifying the current libevent backend in use --- src/luaevent.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/luaevent.c') diff --git a/src/luaevent.c b/src/luaevent.c index 550a386..0c5c37b 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -99,10 +99,17 @@ static int luaevent_loopexit(lua_State*L) { return 1; } +static int luaevent_method(lua_State* L) { + le_base *base = event_base_get(L, 1); + lua_pushstring(L, event_base_get_method(base->base)); + return 1; +} + static luaL_Reg base_funcs[] = { { "addevent", luaevent_addevent }, { "loop", luaevent_loop }, { "loopexit", luaevent_loopexit }, + { "method", luaevent_method }, { NULL, NULL } }; -- cgit v1.2.3 From 2506ebf1e52bdd83007b0463f0a02ea1d6062be8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 7 Dec 2009 22:40:03 +0000 Subject: Add core.libevent_version() function to get version of libevent in use --- src/luaevent.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/luaevent.c') diff --git a/src/luaevent.c b/src/luaevent.c index 0c5c37b..8a682df 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -29,6 +29,11 @@ int luaevent_newbase(lua_State* L) { return 1; } +int luaevent_libevent_version(lua_State* L) { + lua_pushstring(L, event_get_version()); + return 1; +} + static int luaevent_base_gc(lua_State* L) { le_base *base = event_base_get(L, 1); if(base->base) { @@ -115,6 +120,7 @@ static luaL_Reg base_funcs[] = { static luaL_Reg funcs[] = { { "new", luaevent_newbase }, + { "libevent_version", luaevent_libevent_version }, { NULL, NULL } }; -- cgit v1.2.3 From 5435cbb46fc3456a32fe7527c42e6c7419ceccc1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 9 Dec 2009 00:34:39 +0000 Subject: base:addevent(): Accept integer as fd parameter --- src/luaevent.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/luaevent.c') diff --git a/src/luaevent.c b/src/luaevent.c index 8a682df..a8d5f7d 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -45,14 +45,18 @@ static int luaevent_base_gc(lua_State* L) { int getSocketFd(lua_State* L, int idx) { int fd; - luaL_checktype(L, idx, LUA_TUSERDATA); - lua_getfield(L, idx, "getfd"); - if(lua_isnil(L, -1)) - return luaL_error(L, "Socket type missing 'getfd' method"); - lua_pushvalue(L, idx); - lua_call(L, 1, 1); - fd = lua_tointeger(L, -1); - lua_pop(L, 1); + if(lua_isnumber(L, idx)) { + fd = lua_tonumber(L, idx); + } else { + luaL_checktype(L, idx, LUA_TUSERDATA); + lua_getfield(L, idx, "getfd"); + if(lua_isnil(L, -1)) + return luaL_error(L, "Socket type missing 'getfd' method"); + lua_pushvalue(L, idx); + lua_call(L, 1, 1); + fd = lua_tointeger(L, -1); + lua_pop(L, 1); + } return fd; } -- cgit v1.2.3 From 2129e6154e3b48ef9568242af5d74c990c55dd6f Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 15 Feb 2010 06:22:58 +0500 Subject: luaevent.c: Make ANSI C compatible. --- src/luaevent.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/luaevent.c') diff --git a/src/luaevent.c b/src/luaevent.c index a8d5f7d..19fb7d6 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -91,19 +91,21 @@ static int luaevent_addevent(lua_State* L) { } static int luaevent_loop(lua_State* L) { + int ret; le_base *base = event_base_get(L, 1); base->loop_L = L; - int ret = event_base_loop(base->base, 0); + ret = event_base_loop(base->base, 0); lua_pushinteger(L, ret); return 1; } static int luaevent_loopexit(lua_State*L) { + int ret; le_base *base = event_base_get(L, 1); struct timeval tv = { 0, 0 }; if(lua_gettop(L) >= 2) /* Optional timeout before exiting the loop */ load_timeval(luaL_checknumber(L, 2), &tv); - int ret = event_base_loopexit(base->base, &tv); + ret = event_base_loopexit(base->base, &tv); lua_pushinteger(L, ret); return 1; } -- cgit v1.2.3 From 59333212814d8de493295e2a19b046bed81d9a09 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 15 Feb 2010 06:26:34 +0500 Subject: buffer_event.c, event_buffer.c, luaevent.c: Remove redundant #includes. --- src/luaevent.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/luaevent.c') diff --git a/src/luaevent.c b/src/luaevent.c index 19fb7d6..06b84c5 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -1,21 +1,15 @@ /* LuaEvent - Copyright (C) 2007 Thomas Harning * Licensed as LGPL - See doc/COPYING for details */ -#include "luaevent.h" #include "event_callback.h" #include "event_buffer.h" #include "buffer_event.h" -#include #include #include #define EVENT_BASE_MT "EVENT_BASE_MT" -#ifdef _WIN32 -#include -#endif - le_base* event_base_get(lua_State* L, int idx) { return (le_base*)luaL_checkudata(L, idx, EVENT_BASE_MT); } -- cgit v1.2.3 From dcf2339cc6e5820b0c8345475329ff53151a5945 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 15 Feb 2010 14:16:55 +0000 Subject: luaevent.c: Fix for backwards-compatibility with 1.3 --- src/luaevent.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/luaevent.c') diff --git a/src/luaevent.c b/src/luaevent.c index 06b84c5..6036cf1 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -7,6 +7,7 @@ #include #include +#include #define EVENT_BASE_MT "EVENT_BASE_MT" @@ -105,8 +106,13 @@ static int luaevent_loopexit(lua_State*L) { } static int luaevent_method(lua_State* L) { + #ifdef _EVENT_VERSION le_base *base = event_base_get(L, 1); - lua_pushstring(L, event_base_get_method(base->base)); + if(strcmp(_EVENT_VERSION, "1.3")<0) + lua_pushstring(L, event_base_get_method(base->base)); + else + #endif + lua_pushstring(L, event_get_method()); return 1; } -- cgit v1.2.3