summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--src/plugins/lua/weechat-lua-api.c57
-rw-r--r--src/plugins/lua/weechat-lua.c34
-rw-r--r--src/plugins/lua/weechat-lua.h1
4 files changed, 45 insertions, 50 deletions
diff --git a/ChangeLog b/ChangeLog
index 3e9f192f3..51caf493e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,7 @@
WeeChat ChangeLog
=================
Sébastien Helleu <flashcode@flashtux.org>
-v0.4.3-dev, 2013-10-19
+v0.4.3-dev, 2013-10-24
This document lists all changes for each version.
@@ -20,6 +20,7 @@ Version 0.4.3 (under dev!)
* irc: add option irc.look.notice_welcome_tags
* irc: add server option "default_msg_kick" to customize default kick/kickban
message (task #12777)
+* lua: fix crash on calls to callbacks during load of script
Version 0.4.2 (2013-10-06)
--------------------------
diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c
index fd6d50b43..a162ac638 100644
--- a/src/plugins/lua/weechat-lua-api.c
+++ b/src/plugins/lua/weechat-lua-api.c
@@ -791,7 +791,7 @@ weechat_lua_api_config_reload_cb (void *data,
func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
func_argv[1] = API_PTR2STR(config_file);
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ss", func_argv);
@@ -857,7 +857,7 @@ weechat_lua_api_config_read_cb (void *data,
func_argv[3] = (option_name) ? (char *)option_name : empty_arg;
func_argv[4] = (value) ? (char *)value : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"sssss", func_argv);
@@ -898,7 +898,7 @@ weechat_lua_api_config_section_write_cb (void *data,
func_argv[1] = API_PTR2STR(config_file);
func_argv[2] = (section_name) ? (char *)section_name : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"sss", func_argv);
@@ -937,7 +937,7 @@ weechat_lua_api_config_section_write_default_cb (void *data,
func_argv[1] = API_PTR2STR(config_file);
func_argv[2] = (section_name) ? (char *)section_name : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"sss", func_argv);
@@ -980,7 +980,7 @@ weechat_lua_api_config_section_create_option_cb (void *data,
func_argv[3] = (option_name) ? (char *)option_name : empty_arg;
func_argv[4] = (value) ? (char *)value : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"sssss", func_argv);
@@ -1023,7 +1023,7 @@ weechat_lua_api_config_section_delete_option_cb (void *data,
func_argv[2] = API_PTR2STR(section);
func_argv[3] = API_PTR2STR(option);
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ssss", func_argv);
@@ -1140,7 +1140,7 @@ weechat_lua_api_config_option_check_value_cb (void *data,
func_argv[1] = API_PTR2STR(option);
func_argv[2] = (value) ? (char *)value : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"sss", func_argv);
@@ -1177,7 +1177,7 @@ weechat_lua_api_config_option_change_cb (void *data,
func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
func_argv[1] = API_PTR2STR(option);
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ss", func_argv);
@@ -1206,7 +1206,7 @@ weechat_lua_api_config_option_delete_cb (void *data,
func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
func_argv[1] = API_PTR2STR(option);
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ss", func_argv);
@@ -2032,7 +2032,7 @@ weechat_lua_api_hook_command_cb (void *data, struct t_gui_buffer *buffer,
func_argv[1] = API_PTR2STR(buffer);
func_argv[2] = (argc > 1) ? argv_eol[1] : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"sss", func_argv);
@@ -2103,7 +2103,7 @@ weechat_lua_api_hook_command_run_cb (void *data, struct t_gui_buffer *buffer,
func_argv[1] = API_PTR2STR(buffer);
func_argv[2] = (command) ? (char *)command : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"sss", func_argv);
@@ -2166,7 +2166,7 @@ weechat_lua_api_hook_timer_cb (void *data, int remaining_calls)
func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
func_argv[1] = str_remaining_calls;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ss", func_argv);
@@ -2231,7 +2231,7 @@ weechat_lua_api_hook_fd_cb (void *data, int fd)
func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
func_argv[1] = str_fd;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ss", func_argv);
@@ -2301,7 +2301,7 @@ weechat_lua_api_hook_process_cb (void *data,
func_argv[3] = (out) ? (char *)out : empty_arg;
func_argv[4] = (err) ? (char *)err : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ssiss", func_argv);
@@ -2409,7 +2409,7 @@ weechat_lua_api_hook_connect_cb (void *data, int status, int gnutls_rc,
func_argv[4] = (ip_address) ? (char *)ip_address : empty_arg;
func_argv[5] = (error) ? (char *)error : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ssssss", func_argv);
@@ -2500,7 +2500,7 @@ weechat_lua_api_hook_print_cb (void *data, struct t_gui_buffer *buffer,
func_argv[6] = (prefix) ? (char *)prefix : empty_arg;
func_argv[7] = (message) ? (char *)message : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ssssssss", func_argv);
@@ -2593,7 +2593,7 @@ weechat_lua_api_hook_signal_cb (void *data, const char *signal,
else
func_argv[2] = empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"sss", func_argv);
@@ -2693,7 +2693,7 @@ weechat_lua_api_hook_hsignal_cb (void *data, const char *signal,
func_argv[1] = (signal) ? (char *)signal : empty_arg;
func_argv[2] = hashtable;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ssh", func_argv);
@@ -2777,7 +2777,7 @@ weechat_lua_api_hook_config_cb (void *data, const char *option,
func_argv[1] = (option) ? (char *)option : empty_arg;
func_argv[2] = (value) ? (char *)value : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"sss", func_argv);
@@ -2839,7 +2839,7 @@ weechat_lua_api_hook_completion_cb (void *data, const char *completion_item,
func_argv[2] = API_PTR2STR(buffer);
func_argv[3] = API_PTR2STR(completion);
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ssss", func_argv);
@@ -2929,7 +2929,7 @@ weechat_lua_api_hook_modifier_cb (void *data, const char *modifier,
func_argv[2] = (modifier_data) ? (char *)modifier_data : empty_arg;
func_argv[3] = (string) ? (char *)string : empty_arg;
- return (char *)weechat_lua_exec (script_callback->script, NULL,
+ return (char *)weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_STRING,
script_callback->function,
"ssss", func_argv);
@@ -2997,7 +2997,7 @@ weechat_lua_api_hook_info_cb (void *data, const char *info_name,
func_argv[1] = (info_name) ? (char *)info_name : empty_arg;
func_argv[2] = (arguments) ? (char *)arguments : empty_arg;
- return (const char *)weechat_lua_exec (script_callback->script, NULL,
+ return (const char *)weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_STRING,
script_callback->function,
"sss", func_argv);
@@ -3051,7 +3051,6 @@ weechat_lua_api_hook_info_hashtable_cb (void *data, const char *info_name,
func_argv[2] = hashtable;
return (struct t_hashtable *)weechat_lua_exec (script_callback->script,
- NULL,
WEECHAT_SCRIPT_EXEC_HASHTABLE,
script_callback->function,
"ssh", func_argv);
@@ -3110,7 +3109,6 @@ weechat_lua_api_hook_infolist_cb (void *data, const char *info_name,
func_argv[3] = (arguments) ? (char *)arguments : empty_arg;
result = (struct t_infolist *)weechat_lua_exec (script_callback->script,
- NULL,
WEECHAT_SCRIPT_EXEC_STRING,
script_callback->function,
"ssss", func_argv);
@@ -3171,7 +3169,6 @@ weechat_lua_api_hook_focus_cb (void *data,
func_argv[1] = info;
return (struct t_hashtable *)weechat_lua_exec (script_callback->script,
- NULL,
WEECHAT_SCRIPT_EXEC_HASHTABLE,
script_callback->function,
"sh", func_argv);
@@ -3249,7 +3246,7 @@ weechat_lua_api_buffer_input_data_cb (void *data, struct t_gui_buffer *buffer,
func_argv[1] = API_PTR2STR(buffer);
func_argv[2] = (input_data) ? (char *)input_data : empty_arg;
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"sss", func_argv);
@@ -3285,7 +3282,7 @@ weechat_lua_api_buffer_close_cb (void *data, struct t_gui_buffer *buffer)
func_argv[0] = (script_callback->data) ? script_callback->data : empty_arg;
func_argv[1] = API_PTR2STR(buffer);
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ss", func_argv);
@@ -4018,7 +4015,7 @@ weechat_lua_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item,
func_argv[3] = API_PTR2STR(buffer);
func_argv[4] = extra_info;
- ret = (char *)weechat_lua_exec (script_callback->script, NULL,
+ ret = (char *)weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_STRING,
script_callback->function + 7,
"ssssh", func_argv);
@@ -4037,7 +4034,7 @@ weechat_lua_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item,
func_argv[1] = API_PTR2STR(item);
func_argv[2] = API_PTR2STR(window);
- ret = (char *)weechat_lua_exec (script_callback->script, NULL,
+ ret = (char *)weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_STRING,
script_callback->function,
"sss", func_argv);
@@ -5046,7 +5043,7 @@ weechat_lua_api_upgrade_read_cb (void *data,
func_argv[2] = str_object_id;
func_argv[3] = API_PTR2STR(infolist);
- rc = (int *) weechat_lua_exec (script_callback->script, NULL,
+ rc = (int *) weechat_lua_exec (script_callback->script,
WEECHAT_SCRIPT_EXEC_INT,
script_callback->function,
"ssss", func_argv);
diff --git a/src/plugins/lua/weechat-lua.c b/src/plugins/lua/weechat-lua.c
index 86e01c4fb..e9425fa0a 100644
--- a/src/plugins/lua/weechat-lua.c
+++ b/src/plugins/lua/weechat-lua.c
@@ -160,9 +160,8 @@ weechat_lua_tohashtable (lua_State *interpreter, int index, int size,
*/
void *
-weechat_lua_exec (struct t_plugin_script *script, lua_State *interpreter,
- int ret_type, const char *function, const char *format,
- void **argv)
+weechat_lua_exec (struct t_plugin_script *script, int ret_type,
+ const char *function, const char *format, void **argv)
{
void *ret_value;
int argc, i, *ret_i;
@@ -170,12 +169,10 @@ weechat_lua_exec (struct t_plugin_script *script, lua_State *interpreter,
struct t_plugin_script *old_lua_current_script;
old_lua_current_interpreter = lua_current_interpreter;
- lua_current_interpreter = script->interpreter;
+ if (script->interpreter)
+ lua_current_interpreter = script->interpreter;
- if (!interpreter)
- interpreter = lua_current_interpreter;
-
- lua_getglobal (interpreter, function);
+ lua_getglobal (lua_current_interpreter, function);
old_lua_current_script = lua_current_script;
lua_current_script = script;
@@ -189,13 +186,14 @@ weechat_lua_exec (struct t_plugin_script *script, lua_State *interpreter,
switch (format[i])
{
case 's': /* string */
- lua_pushstring (interpreter, (char *)argv[i]);
+ lua_pushstring (lua_current_interpreter, (char *)argv[i]);
break;
case 'i': /* integer */
- lua_pushnumber (interpreter, *((int *)argv[i]));
+ lua_pushnumber (lua_current_interpreter, *((int *)argv[i]));
break;
case 'h': /* hash */
- weechat_lua_pushhashtable (interpreter, (struct t_hashtable *)argv[i]);
+ weechat_lua_pushhashtable (lua_current_interpreter,
+ (struct t_hashtable *)argv[i]);
break;
}
}
@@ -203,22 +201,22 @@ weechat_lua_exec (struct t_plugin_script *script, lua_State *interpreter,
ret_value = NULL;
- if (lua_pcall (interpreter, argc, 1, 0) == 0)
+ if (lua_pcall (lua_current_interpreter, argc, 1, 0) == 0)
{
if (ret_type == WEECHAT_SCRIPT_EXEC_STRING)
{
- ret_value = strdup ((char *) lua_tostring (interpreter, -1));
+ ret_value = strdup ((char *) lua_tostring (lua_current_interpreter, -1));
}
else if (ret_type == WEECHAT_SCRIPT_EXEC_INT)
{
ret_i = malloc (sizeof (*ret_i));
if (ret_i)
- *ret_i = lua_tonumber (interpreter, -1);
+ *ret_i = lua_tonumber (lua_current_interpreter, -1);
ret_value = ret_i;
}
else if (ret_type == WEECHAT_SCRIPT_EXEC_HASHTABLE)
{
- ret_value = weechat_lua_tohashtable (interpreter, -1,
+ ret_value = weechat_lua_tohashtable (lua_current_interpreter, -1,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);
@@ -236,10 +234,10 @@ weechat_lua_exec (struct t_plugin_script *script, lua_State *interpreter,
weechat_printf (NULL,
weechat_gettext ("%s%s: error: %s"),
weechat_prefix ("error"), LUA_PLUGIN_NAME,
- lua_tostring (interpreter, -1));
+ lua_tostring (lua_current_interpreter, -1));
}
- lua_pop (interpreter, 1);
+ lua_pop (lua_current_interpreter, 1);
lua_current_script = old_lua_current_script;
lua_current_interpreter = old_lua_current_interpreter;
@@ -498,7 +496,7 @@ weechat_lua_unload (struct t_plugin_script *script)
if (script->shutdown_func && script->shutdown_func[0])
{
- rc = (int *)weechat_lua_exec (script, NULL,
+ rc = (int *)weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_INT,
script->shutdown_func,
NULL, NULL);
diff --git a/src/plugins/lua/weechat-lua.h b/src/plugins/lua/weechat-lua.h
index d4f48da92..194e2956a 100644
--- a/src/plugins/lua/weechat-lua.h
+++ b/src/plugins/lua/weechat-lua.h
@@ -51,7 +51,6 @@ extern struct t_hashtable *weechat_lua_tohashtable (lua_State *interpreter,
const char *type_keys,
const char *type_values);
extern void *weechat_lua_exec (struct t_plugin_script *script,
- lua_State *interpreter,
int ret_type,
const char *function,
const char *format, void **argv);