diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-01-25 22:26:55 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-01-25 22:26:55 +0300 |
commit | 61078f0274de4d99c153349dc01a27567c50e489 (patch) | |
tree | 3105454787fbe1faecf201a9fcb300a0d589fbbb /src/lua/lua_config.c | |
parent | 9eed219c78128a0cb0939000abd10f5cd730e52f (diff) | |
download | rspamd-61078f0274de4d99c153349dc01a27567c50e489.tar.gz rspamd-61078f0274de4d99c153349dc01a27567c50e489.zip |
* Make trie plugin and fix trie lua API
Diffstat (limited to 'src/lua/lua_config.c')
-rw-r--r-- | src/lua/lua_config.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 3b81ce64e..8259ae9a4 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -89,13 +89,16 @@ LUA_FUNCTION_DEF (trie, search_text); LUA_FUNCTION_DEF (trie, search_task); static const struct luaL_reg trielib_m[] = { - LUA_INTERFACE_DEF (trie, create), LUA_INTERFACE_DEF (trie, add_pattern), LUA_INTERFACE_DEF (trie, search_text), LUA_INTERFACE_DEF (trie, search_task), {"__tostring", lua_class_tostring}, {NULL, NULL} }; +static const struct luaL_reg trielib_f[] = { + LUA_INTERFACE_DEF (trie, create), + {NULL, NULL} +}; static struct config_file * lua_check_config (lua_State * L) @@ -125,8 +128,9 @@ static rspamd_trie_t * lua_check_trie (lua_State * L) { void *ud = luaL_checkudata (L, 1, "rspamd{trie}"); + luaL_argcheck (L, ud != NULL, 1, "'trie' expected"); - return **((rspamd_trie_t ***)ud); + return *((rspamd_trie_t **)ud); } /*** Config functions ***/ @@ -749,8 +753,17 @@ luaopen_hash_table (lua_State * L) gint luaopen_trie (lua_State * L) { - lua_newclass (L, "rspamd{trie}", trielib_m); - luaL_openlib (L, "rspamd_trie", null_reg, 0); + luaL_newmetatable (L, "rspamd{trie}"); + lua_pushstring (L, "__index"); + lua_pushvalue (L, -2); + lua_settable (L, -3); + + lua_pushstring (L, "class"); + lua_pushstring (L, "rspamd{trie}"); + lua_rawset (L, -3); + + luaL_openlib (L, NULL, trielib_m, 0); + luaL_openlib(L, "rspamd_trie", trielib_f, 0); return 1; } |