1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Check for Lua hooks before calling

This commit is contained in:
James Booth 2013-09-15 22:17:32 +01:00
parent aa13586bc7
commit d1ccfb148b

View File

@ -105,11 +105,13 @@ lua_init_hook(ProfPlugin *plugin, const char * const version, const char * const
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_init"); lua_pushstring(L, "prof_init");
lua_gettable(L, -2); lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, version); lua_pushstring(L, version);
lua_pushstring(L, status); lua_pushstring(L, status);
int res2 = lua_pcall(L, 2, 0, 0); int res2 = lua_pcall(L, 2, 0, 0);
lua_check_error(res2); lua_check_error(res2);
lua_pop(L, 1); lua_pop(L, 1);
}
} }
void void
@ -119,9 +121,11 @@ lua_on_start_hook(ProfPlugin *plugin)
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_start"); lua_pushstring(L, "prof_on_start");
lua_gettable(L, -2); lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
int res2 = lua_pcall(L, 0, 0, 0); int res2 = lua_pcall(L, 0, 0, 0);
lua_check_error(res2); lua_check_error(res2);
lua_pop(L, 1); lua_pop(L, 1);
}
} }
void void
@ -132,11 +136,13 @@ lua_on_connect_hook(ProfPlugin *plugin, const char * const account_name,
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_connect"); lua_pushstring(L, "prof_on_connect");
lua_gettable(L, -2); lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, account_name); lua_pushstring(L, account_name);
lua_pushstring(L, fulljid); lua_pushstring(L, fulljid);
int res2 = lua_pcall(L, 2, 0, 0); int res2 = lua_pcall(L, 2, 0, 0);
lua_check_error(res2); lua_check_error(res2);
lua_pop(L, 1); lua_pop(L, 1);
}
} }
void void
@ -147,11 +153,13 @@ lua_on_disconnect_hook(ProfPlugin *plugin, const char * const account_name,
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_disconnect"); lua_pushstring(L, "prof_on_disconnect");
lua_gettable(L, -2); lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, account_name); lua_pushstring(L, account_name);
lua_pushstring(L, fulljid); lua_pushstring(L, fulljid);
int res2 = lua_pcall(L, 2, 0, 0); int res2 = lua_pcall(L, 2, 0, 0);
lua_check_error(res2); lua_check_error(res2);
lua_pop(L, 1); lua_pop(L, 1);
}
} }
char * char *
@ -162,6 +170,7 @@ lua_on_message_received_hook(ProfPlugin *plugin, const char * const jid,
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_message_received"); lua_pushstring(L, "prof_on_message_received");
lua_gettable(L, -2); lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, jid); lua_pushstring(L, jid);
lua_pushstring(L, message); lua_pushstring(L, message);
int res2 = lua_pcall(L, 2, 1, 0); int res2 = lua_pcall(L, 2, 1, 0);
@ -175,6 +184,9 @@ lua_on_message_received_hook(ProfPlugin *plugin, const char * const jid,
lua_pop(L, 2); lua_pop(L, 2);
return result; return result;
}
return NULL;
} }
char * char *
@ -185,6 +197,7 @@ lua_on_private_message_received_hook(ProfPlugin *plugin, const char * const room
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_private_message_received"); lua_pushstring(L, "prof_on_private_message_received");
lua_gettable(L, -2); lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, room); lua_pushstring(L, room);
lua_pushstring(L, nick); lua_pushstring(L, nick);
lua_pushstring(L, message); lua_pushstring(L, message);
@ -199,6 +212,9 @@ lua_on_private_message_received_hook(ProfPlugin *plugin, const char * const room
lua_pop(L, 2); lua_pop(L, 2);
return result; return result;
}
return NULL;
} }
char * char *
@ -209,6 +225,7 @@ lua_on_room_message_received_hook(ProfPlugin *plugin, const char * const room,
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_room_message_received"); lua_pushstring(L, "prof_on_room_message_received");
lua_gettable(L, -2); lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, room); lua_pushstring(L, room);
lua_pushstring(L, nick); lua_pushstring(L, nick);
lua_pushstring(L, message); lua_pushstring(L, message);
@ -223,6 +240,9 @@ lua_on_room_message_received_hook(ProfPlugin *plugin, const char * const room,
lua_pop(L, 2); lua_pop(L, 2);
return result; return result;
}
return NULL;
} }
char * char *
@ -233,6 +253,7 @@ lua_on_message_send_hook(ProfPlugin *plugin, const char * const jid,
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_message_send"); lua_pushstring(L, "prof_on_message_send");
lua_gettable(L, -2); lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, jid); lua_pushstring(L, jid);
lua_pushstring(L, message); lua_pushstring(L, message);
int res2 = lua_pcall(L, 2, 1, 0); int res2 = lua_pcall(L, 2, 1, 0);
@ -246,6 +267,9 @@ lua_on_message_send_hook(ProfPlugin *plugin, const char * const jid,
lua_pop(L, 2); lua_pop(L, 2);
return result; return result;
}
return NULL;
} }
char * char *
@ -256,6 +280,7 @@ lua_on_private_message_send_hook(ProfPlugin *plugin, const char * const room,
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_private_message_send"); lua_pushstring(L, "prof_on_private_message_send");
lua_gettable(L, -2); lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, room); lua_pushstring(L, room);
lua_pushstring(L, nick); lua_pushstring(L, nick);
lua_pushstring(L, message); lua_pushstring(L, message);
@ -270,6 +295,9 @@ lua_on_private_message_send_hook(ProfPlugin *plugin, const char * const room,
lua_pop(L, 2); lua_pop(L, 2);
return result; return result;
}
return NULL;
} }
char * char *
@ -280,6 +308,7 @@ lua_on_room_message_send_hook(ProfPlugin *plugin, const char * const room,
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_room_message_send"); lua_pushstring(L, "prof_on_room_message_send");
lua_gettable(L, -2); lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, room); lua_pushstring(L, room);
lua_pushstring(L, message); lua_pushstring(L, message);
int res2 = lua_pcall(L, 2, 1, 0); int res2 = lua_pcall(L, 2, 1, 0);
@ -293,6 +322,9 @@ lua_on_room_message_send_hook(ProfPlugin *plugin, const char * const room,
lua_pop(L, 2); lua_pop(L, 2);
return result; return result;
}
return NULL;
} }
void void
@ -302,9 +334,11 @@ lua_on_shutdown_hook(ProfPlugin *plugin)
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_shutdown"); lua_pushstring(L, "prof_on_shutdown");
lua_gettable(L, -2); lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
int res2 = lua_pcall(L, 0, 0, 0); int res2 = lua_pcall(L, 0, 0, 0);
lua_check_error(res2); lua_check_error(res2);
lua_pop(L, 1); lua_pop(L, 1);
}
} }
void void