aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_common.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-03-04 12:47:45 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-03-04 20:03:59 +0000
commitc5836a23f9bb91872f33375914baa02bca4001ca (patch)
tree159e7aad17ec0463e42b4f5da9efad85b7e33348 /src/lua/lua_common.c
parent85e0054fe5de757742867546c408590bada8bd0d (diff)
downloadrspamd-c5836a23f9bb91872f33375914baa02bca4001ca.tar.gz
rspamd-c5836a23f9bb91872f33375914baa02bca4001ca.zip
[Minor] Add helper to alter metatables
Diffstat (limited to 'src/lua/lua_common.c')
-rw-r--r--src/lua/lua_common.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index 2087fe592..ce5fff6c5 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -197,6 +197,24 @@ rspamd_lua_setclass (lua_State * L, const gchar *classname, gint objidx)
lua_setmetatable (L, objidx);
}
+void
+rspamd_lua_add_metamethod (lua_State *L, const gchar *classname,
+ luaL_Reg *meth)
+{
+ khiter_t k;
+
+ k = kh_get (lua_class_set, lua_classes, classname);
+
+ g_assert (k != kh_end (lua_classes));
+ /* get metatable identified by pointer */
+ lua_rawgetp (L, LUA_REGISTRYINDEX,
+ RSPAMD_LIGHTUSERDATA_MASK (kh_key (lua_classes, k)));
+
+ lua_pushcfunction (L, meth->func);
+ lua_setfield (L, -2, meth->name);
+ lua_pop (L, 1); /* remove metatable */
+}
+
/* assume that table is at the top */
void
rspamd_lua_table_set (lua_State * L, const gchar *index, const gchar *value)