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_pushstring(L, "prof_init");
lua_gettable(L, -2);
lua_pushstring(L, version);
lua_pushstring(L, status);
int res2 = lua_pcall(L, 2, 0, 0);
lua_check_error(res2);
lua_pop(L, 1);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, version);
lua_pushstring(L, status);
int res2 = lua_pcall(L, 2, 0, 0);
lua_check_error(res2);
lua_pop(L, 1);
}
}
void
@ -119,9 +121,11 @@ lua_on_start_hook(ProfPlugin *plugin)
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_start");
lua_gettable(L, -2);
int res2 = lua_pcall(L, 0, 0, 0);
lua_check_error(res2);
lua_pop(L, 1);
if (!lua_isnil(L, -1)) {
int res2 = lua_pcall(L, 0, 0, 0);
lua_check_error(res2);
lua_pop(L, 1);
}
}
void
@ -132,11 +136,13 @@ lua_on_connect_hook(ProfPlugin *plugin, const char * const account_name,
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_connect");
lua_gettable(L, -2);
lua_pushstring(L, account_name);
lua_pushstring(L, fulljid);
int res2 = lua_pcall(L, 2, 0, 0);
lua_check_error(res2);
lua_pop(L, 1);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, account_name);
lua_pushstring(L, fulljid);
int res2 = lua_pcall(L, 2, 0, 0);
lua_check_error(res2);
lua_pop(L, 1);
}
}
void
@ -147,11 +153,13 @@ lua_on_disconnect_hook(ProfPlugin *plugin, const char * const account_name,
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_disconnect");
lua_gettable(L, -2);
lua_pushstring(L, account_name);
lua_pushstring(L, fulljid);
int res2 = lua_pcall(L, 2, 0, 0);
lua_check_error(res2);
lua_pop(L, 1);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, account_name);
lua_pushstring(L, fulljid);
int res2 = lua_pcall(L, 2, 0, 0);
lua_check_error(res2);
lua_pop(L, 1);
}
}
char *
@ -162,19 +170,23 @@ lua_on_message_received_hook(ProfPlugin *plugin, const char * const jid,
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_message_received");
lua_gettable(L, -2);
lua_pushstring(L, jid);
lua_pushstring(L, message);
int res2 = lua_pcall(L, 2, 1, 0);
lua_check_error(res2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, jid);
lua_pushstring(L, message);
int res2 = lua_pcall(L, 2, 1, 0);
lua_check_error(res2);
char *result = NULL;
if (lua_isstring(L, -1)) {
result = strdup(lua_tostring(L, -1));
char *result = NULL;
if (lua_isstring(L, -1)) {
result = strdup(lua_tostring(L, -1));
}
lua_pop(L, 2);
return result;
}
lua_pop(L, 2);
return result;
return NULL;
}
char *
@ -185,20 +197,24 @@ lua_on_private_message_received_hook(ProfPlugin *plugin, const char * const room
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_private_message_received");
lua_gettable(L, -2);
lua_pushstring(L, room);
lua_pushstring(L, nick);
lua_pushstring(L, message);
int res2 = lua_pcall(L, 3, 1, 0);
lua_check_error(res2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, room);
lua_pushstring(L, nick);
lua_pushstring(L, message);
int res2 = lua_pcall(L, 3, 1, 0);
lua_check_error(res2);
char *result = NULL;
if (lua_isstring(L, -1)) {
result = strdup(lua_tostring(L, -1));
char *result = NULL;
if (lua_isstring(L, -1)) {
result = strdup(lua_tostring(L, -1));
}
lua_pop(L, 2);
return result;
}
lua_pop(L, 2);
return result;
return NULL;
}
char *
@ -209,20 +225,24 @@ lua_on_room_message_received_hook(ProfPlugin *plugin, const char * const room,
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_room_message_received");
lua_gettable(L, -2);
lua_pushstring(L, room);
lua_pushstring(L, nick);
lua_pushstring(L, message);
int res2 = lua_pcall(L, 3, 1, 0);
lua_check_error(res2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, room);
lua_pushstring(L, nick);
lua_pushstring(L, message);
int res2 = lua_pcall(L, 3, 1, 0);
lua_check_error(res2);
char *result = NULL;
if (lua_isstring(L, -1)) {
result = strdup(lua_tostring(L, -1));
char *result = NULL;
if (lua_isstring(L, -1)) {
result = strdup(lua_tostring(L, -1));
}
lua_pop(L, 2);
return result;
}
lua_pop(L, 2);
return result;
return NULL;
}
char *
@ -233,19 +253,23 @@ lua_on_message_send_hook(ProfPlugin *plugin, const char * const jid,
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_message_send");
lua_gettable(L, -2);
lua_pushstring(L, jid);
lua_pushstring(L, message);
int res2 = lua_pcall(L, 2, 1, 0);
lua_check_error(res2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, jid);
lua_pushstring(L, message);
int res2 = lua_pcall(L, 2, 1, 0);
lua_check_error(res2);
char *result = NULL;
if (lua_isstring(L, -1)) {
result = strdup(lua_tostring(L, -1));
char *result = NULL;
if (lua_isstring(L, -1)) {
result = strdup(lua_tostring(L, -1));
}
lua_pop(L, 2);
return result;
}
lua_pop(L, 2);
return result;
return NULL;
}
char *
@ -256,20 +280,24 @@ lua_on_private_message_send_hook(ProfPlugin *plugin, const char * const room,
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_private_message_send");
lua_gettable(L, -2);
lua_pushstring(L, room);
lua_pushstring(L, nick);
lua_pushstring(L, message);
int res2 = lua_pcall(L, 3, 1, 0);
lua_check_error(res2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, room);
lua_pushstring(L, nick);
lua_pushstring(L, message);
int res2 = lua_pcall(L, 3, 1, 0);
lua_check_error(res2);
char *result = NULL;
if (lua_isstring(L, -1)) {
result = strdup(lua_tostring(L, -1));
char *result = NULL;
if (lua_isstring(L, -1)) {
result = strdup(lua_tostring(L, -1));
}
lua_pop(L, 2);
return result;
}
lua_pop(L, 2);
return result;
return NULL;
}
char *
@ -280,19 +308,23 @@ lua_on_room_message_send_hook(ProfPlugin *plugin, const char * const room,
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_room_message_send");
lua_gettable(L, -2);
lua_pushstring(L, room);
lua_pushstring(L, message);
int res2 = lua_pcall(L, 2, 1, 0);
lua_check_error(res2);
if (!lua_isnil(L, -1)) {
lua_pushstring(L, room);
lua_pushstring(L, message);
int res2 = lua_pcall(L, 2, 1, 0);
lua_check_error(res2);
char *result = NULL;
if (lua_isstring(L, -1)) {
result = strdup(lua_tostring(L, -1));
char *result = NULL;
if (lua_isstring(L, -1)) {
result = strdup(lua_tostring(L, -1));
}
lua_pop(L, 2);
return result;
}
lua_pop(L, 2);
return result;
return NULL;
}
void
@ -302,9 +334,11 @@ lua_on_shutdown_hook(ProfPlugin *plugin)
lua_rawgeti(L, LUA_REGISTRYINDEX, *p_ref);
lua_pushstring(L, "prof_on_shutdown");
lua_gettable(L, -2);
int res2 = lua_pcall(L, 0, 0, 0);
lua_check_error(res2);
lua_pop(L, 1);
if (!lua_isnil(L, -1)) {
int res2 = lua_pcall(L, 0, 0, 0);
lua_check_error(res2);
lua_pop(L, 1);
}
}
void