diff options
author | Andrew Lewis <nerf@judo.za.org> | 2017-03-04 12:28:34 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2017-03-04 12:28:52 +0200 |
commit | ed7873475a3fbbb84add58e75843ec57bef035ba (patch) | |
tree | 52e12b4c28f2aa1ff2fb6b2490ee926b37778949 /src | |
parent | fadd570a71a8b86e8d9be5ff9dbe53f2ead4ac9f (diff) | |
download | rspamd-ed7873475a3fbbb84add58e75843ec57bef035ba.tar.gz rspamd-ed7873475a3fbbb84add58e75843ec57bef035ba.zip |
[Feature] Support running event loop from Lua
Diffstat (limited to 'src')
-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; +} |