]> PatchyGit - patchyircd.git/commitdiff
use luaL_setfuncs to register globals
authorEgor <egor@patchysicp.xyz>
Fri, 26 Jan 2024 14:04:04 +0000 (16:04 +0200)
committerEgor <egor@patchysicp.xyz>
Fri, 26 Jan 2024 14:04:04 +0000 (16:04 +0200)
src/admin.c

index e3e99b1..0d8328d 100644 (file)
@@ -380,26 +380,24 @@ void admin_init(void)
        lua_setglobal(L, "commands");
        lua_newtable(L);
        lua_setglobal(L, "hooks");
-       lua_pushcfunction(L, fn_client_privmsg);
-       lua_setglobal(L, "client_privmsg");
-       lua_pushcfunction(L, fn_client_notice);
-       lua_setglobal(L, "client_notice");
-       lua_pushcfunction(L, fn_channel_join);
-       lua_setglobal(L, "channel_join");
-       lua_pushcfunction(L, fn_channel_part);
-       lua_setglobal(L, "channel_part");
-       lua_pushcfunction(L, fn_channel_new);
-       lua_setglobal(L, "channel_new");
-       lua_pushcfunction(L, fn_channel_mode);
-       lua_setglobal(L, "channel_mode");
-       lua_pushcfunction(L, fn_channel_topic);
-       lua_setglobal(L, "channel_topic");
-       lua_pushcfunction(L, fn_client_chghost);
-       lua_setglobal(L, "client_chghost");
-       lua_pushcfunction(L, fn_rpl_whoisspecial);
-       lua_setglobal(L, "rpl_whoisspecial");
-       lua_pushcfunction(L, fn_db_read_rhs);
-       lua_setglobal(L, "db_read_rhs");
+       {
+               luaL_Reg funcs[] = {
+                       {"client_privmsg", fn_client_privmsg},
+                       {"client_notice", fn_client_notice},
+                       {"channel_join", fn_channel_join},
+                       {"channel_part", fn_channel_part},
+                       {"channel_new", fn_channel_new},
+                       {"channel_mode", fn_channel_mode},
+                       {"channel_topic", fn_channel_topic},
+                       {"client_chghost", fn_client_chghost},
+                       {"rpl_whoisspecial", fn_rpl_whoisspecial},
+                       {"db_read_rhs", fn_db_read_rhs},
+                       {0, 0},
+               };
+               lua_pushglobaltable(L);
+               luaL_setfuncs(L, funcs, 0);
+               lua_pop(L, 1);
+       }
 }
 void admin_fini(void)
 {