1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-24 20:06: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
+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);