diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-16 13:10:42 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-16 13:10:42 +0100 |
commit | 5ef148649daca54714bd141bd473072250b46d83 (patch) | |
tree | 658841acc4d3a4cd208af3fc31449749c64e761f /src/lua/lua_cryptobox.c | |
parent | 35818aec2c5f6e70423fa2954fc9a344b5fe56f0 (diff) | |
download | rspamd-5ef148649daca54714bd141bd473072250b46d83.tar.gz rspamd-5ef148649daca54714bd141bd473072250b46d83.zip |
[Rework] Lua core: Use lightuserdata to index classes
Diffstat (limited to 'src/lua/lua_cryptobox.c')
-rw-r--r-- | src/lua/lua_cryptobox.c | 50 |
1 files changed, 8 insertions, 42 deletions
diff --git a/src/lua/lua_cryptobox.c b/src/lua/lua_cryptobox.c index 35faa0037..645b2495f 100644 --- a/src/lua/lua_cryptobox.c +++ b/src/lua/lua_cryptobox.c @@ -2437,54 +2437,20 @@ lua_load_cryptobox (lua_State * L) void luaopen_cryptobox (lua_State * L) { - luaL_newmetatable (L, "rspamd{cryptobox_pubkey}"); - lua_pushstring (L, "__index"); - lua_pushvalue (L, -2); - lua_settable (L, -3); - - lua_pushstring (L, "class"); - lua_pushstring (L, "rspamd{cryptobox_pubkey}"); - lua_rawset (L, -3); - - luaL_register (L, NULL, cryptoboxpubkeylib_m); + rspamd_lua_new_class (L, "rspamd{cryptobox_pubkey}", cryptoboxpubkeylib_m); + lua_pop (L, 1); rspamd_lua_add_preload (L, "rspamd_cryptobox_pubkey", lua_load_pubkey); - luaL_newmetatable (L, "rspamd{cryptobox_keypair}"); - lua_pushstring (L, "__index"); - lua_pushvalue (L, -2); - lua_settable (L, -3); - - lua_pushstring (L, "class"); - lua_pushstring (L, "rspamd{cryptobox_keypair}"); - lua_rawset (L, -3); - - luaL_register (L, NULL, cryptoboxkeypairlib_m); + rspamd_lua_new_class (L, "rspamd{cryptobox_keypair}", cryptoboxkeypairlib_m); + lua_pop (L, 1); rspamd_lua_add_preload (L, "rspamd_cryptobox_keypair", lua_load_keypair); - luaL_newmetatable (L, "rspamd{cryptobox_signature}"); - - lua_pushstring (L, "__index"); - lua_pushvalue (L, -2); - lua_settable (L, -3); - - lua_pushstring (L, "class"); - lua_pushstring (L, "rspamd{cryptobox_signature}"); - lua_rawset (L, -3); - - luaL_register (L, NULL, cryptoboxsignlib_m); + rspamd_lua_new_class (L, "rspamd{cryptobox_signature}", cryptoboxsignlib_m); + lua_pop (L, 1); rspamd_lua_add_preload (L, "rspamd_cryptobox_signature", lua_load_signature); - luaL_newmetatable (L, "rspamd{cryptobox_hash}"); - - lua_pushstring (L, "__index"); - lua_pushvalue (L, -2); - lua_settable (L, -3); - - lua_pushstring (L, "class"); - lua_pushstring (L, "rspamd{cryptobox_hash}"); - lua_rawset (L, -3); - - luaL_register (L, NULL, cryptoboxhashlib_m); + rspamd_lua_new_class (L, "rspamd{cryptobox_hash}", cryptoboxhashlib_m); + lua_pop (L, 1); rspamd_lua_add_preload (L, "rspamd_cryptobox_hash", lua_load_hash); rspamd_lua_add_preload (L, "rspamd_cryptobox", lua_load_cryptobox); |