diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-03-06 11:10:48 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-06 11:10:48 +0000 |
commit | 4240400bc04d6c06ce5e1cebdbd77441ff2fb35f (patch) | |
tree | 857b921d485c2f36ebcc5e99b3abdf5262db3999 | |
parent | 0d5ef851b1acafb2892178376edb1b4ebb3a5092 (diff) | |
parent | ed7873475a3fbbb84add58e75843ec57bef035ba (diff) | |
download | rspamd-4240400bc04d6c06ce5e1cebdbd77441ff2fb35f.tar.gz rspamd-4240400bc04d6c06ce5e1cebdbd77441ff2fb35f.zip |
Merge pull request #1475 from fatalbanana/evloop
[Feature] Support running event loop from Lua
-rw-r--r-- | src/lua/lua_util.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 2515a8073..0b4d8dd9c 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -530,6 +530,14 @@ static const struct luaL_reg int64lib_m[] = { {NULL, NULL} }; +LUA_FUNCTION_DEF (ev_base, loop); + +static const struct luaL_reg ev_baselib_m[] = { + LUA_INTERFACE_DEF (ev_base, loop), + {"__tostring", rspamd_lua_class_tostring}, + {NULL, NULL} +}; + static gint64 lua_check_int64 (lua_State * L, gint pos) { @@ -2692,6 +2700,8 @@ lua_load_util (lua_State * L) void luaopen_util (lua_State * L) { + rspamd_lua_new_class (L, "rspamd{ev_base}", ev_baselib_m); + lua_pop (L, 1); rspamd_lua_new_class (L, "rspamd{int64}", int64lib_m); lua_pop (L, 1); rspamd_lua_add_preload (L, "rspamd_util", lua_load_util); @@ -2732,3 +2742,20 @@ lua_int64_hex (lua_State *L) return 1; } + +static int +lua_ev_base_loop (lua_State *L) +{ + int flags = 0; + struct event_base *ev_base; + + ev_base = lua_check_ev_base (L, 1); + if (lua_isnumber (L, 2)) { + flags = lua_tonumber (L, 2); + } + + int ret = event_base_loop (ev_base, flags); + lua_pushnumber (L, ret); + + return 1; +} |