1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-25 04:16:38 +02:00

lua: fix interpreter used in API functions (bug #39470)

This commit is contained in:
Sebastien Helleu
2013-07-13 07:22:02 +02:00
parent bd3a12378e
commit 4668f0bef5
4 changed files with 696 additions and 687 deletions
+2 -1
View File
@@ -1,7 +1,7 @@
WeeChat ChangeLog
=================
Sébastien Helleu <flashcode@flashtux.org>
v0.4.2-dev, 2013-07-11
v0.4.2-dev, 2013-07-13
This document lists all changes for each version.
@@ -41,6 +41,7 @@ Version 0.4.2 (under dev!)
(patch #8062)
* irc: fix multiple nicks in command /query (separated by commas): open one
buffer per nick
* lua: fix interpreter used in API functions (bug #39470)
* relay: add command "ping" in weechat protocol (task #12689)
* relay: fix binding to an IP address (bug #39119)
* xfer: add option xfer.look.pv_tags
File diff suppressed because it is too large Load Diff
+17 -14
View File
@@ -160,9 +160,9 @@ weechat_lua_tohashtable (lua_State *interpreter, int index, int size,
*/
void *
weechat_lua_exec (struct t_plugin_script *script, int ret_type,
const char *function,
const char *format, void **argv)
weechat_lua_exec (struct t_plugin_script *script, lua_State *interpreter,
int ret_type, const char *function, const char *format,
void **argv)
{
void *ret_value;
int argc, i, *ret_i;
@@ -172,7 +172,10 @@ weechat_lua_exec (struct t_plugin_script *script, int ret_type,
old_lua_current_interpreter = lua_current_interpreter;
lua_current_interpreter = script->interpreter;
lua_getglobal (lua_current_interpreter, function);
if (!interpreter)
interpreter = lua_current_interpreter;
lua_getglobal (interpreter, function);
old_lua_current_script = lua_current_script;
lua_current_script = script;
@@ -186,13 +189,13 @@ weechat_lua_exec (struct t_plugin_script *script, int ret_type,
switch (format[i])
{
case 's': /* string */
lua_pushstring (lua_current_interpreter, (char *)argv[i]);
lua_pushstring (interpreter, (char *)argv[i]);
break;
case 'i': /* integer */
lua_pushnumber (lua_current_interpreter, *((int *)argv[i]));
lua_pushnumber (interpreter, *((int *)argv[i]));
break;
case 'h': /* hash */
weechat_lua_pushhashtable (lua_current_interpreter, (struct t_hashtable *)argv[i]);
weechat_lua_pushhashtable (interpreter, (struct t_hashtable *)argv[i]);
break;
}
}
@@ -200,22 +203,22 @@ weechat_lua_exec (struct t_plugin_script *script, int ret_type,
ret_value = NULL;
if (lua_pcall (lua_current_interpreter, argc, 1, 0) == 0)
if (lua_pcall (interpreter, argc, 1, 0) == 0)
{
if (ret_type == WEECHAT_SCRIPT_EXEC_STRING)
{
ret_value = strdup ((char *) lua_tostring (lua_current_interpreter, -1));
ret_value = strdup ((char *) lua_tostring (interpreter, -1));
}
else if (ret_type == WEECHAT_SCRIPT_EXEC_INT)
{
ret_i = malloc (sizeof (*ret_i));
if (ret_i)
*ret_i = lua_tonumber (lua_current_interpreter, -1);
*ret_i = lua_tonumber (interpreter, -1);
ret_value = ret_i;
}
else if (ret_type == WEECHAT_SCRIPT_EXEC_HASHTABLE)
{
ret_value = weechat_lua_tohashtable (lua_current_interpreter, -1,
ret_value = weechat_lua_tohashtable (interpreter, -1,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);
@@ -233,10 +236,10 @@ weechat_lua_exec (struct t_plugin_script *script, int ret_type,
weechat_printf (NULL,
weechat_gettext ("%s%s: error: %s"),
weechat_prefix ("error"), LUA_PLUGIN_NAME,
lua_tostring (lua_current_interpreter, -1));
lua_tostring (interpreter, -1));
}
lua_pop (lua_current_interpreter, 1);
lua_pop (interpreter, 1);
lua_current_script = old_lua_current_script;
lua_current_interpreter = old_lua_current_interpreter;
@@ -495,7 +498,7 @@ weechat_lua_unload (struct t_plugin_script *script)
if (script->shutdown_func && script->shutdown_func[0])
{
rc = (int *)weechat_lua_exec (script,
rc = (int *)weechat_lua_exec (script, NULL,
WEECHAT_SCRIPT_EXEC_INT,
script->shutdown_func,
NULL, NULL);
+3 -1
View File
@@ -50,7 +50,9 @@ extern struct t_hashtable *weechat_lua_tohashtable (lua_State *interpreter,
int size,
const char *type_keys,
const char *type_values);
extern void *weechat_lua_exec (struct t_plugin_script *script, int ret_type,
extern void *weechat_lua_exec (struct t_plugin_script *script,
lua_State *interpreter,
int ret_type,
const char *function,
const char *format, void **argv);
extern void weechat_lua_register_lib(lua_State *L, const char *libname,