From: Pavel Rochnyack Date: Wed, 1 May 2019 09:10:35 +0000 (+0700) Subject: lua plugin: don't elements from stack in `clua_store_thread`. X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=cc459b3cccf832e08d5c5bae12add775a915ae01 lua plugin: don't elements from stack in `clua_store_thread`. Debug, before: lua plugin: nargs after store_callback: 1 lua plugin: nargs after lua_newthread: 2 lua plugin: nargs after store_thread: 0 After: lua plugin: nargs after store_callback: 1 lua plugin: nargs after lua_newthread: 2 lua plugin: nargs after store_thread: 1 So, stack is in expected state. --- diff --git a/src/lua.c b/src/lua.c index a0364d7e..8dc78d00 100644 --- a/src/lua.c +++ b/src/lua.c @@ -79,18 +79,14 @@ static int clua_load_callback(lua_State *L, int callback_ref) /* {{{ */ * garbage collector. */ static int clua_store_thread(lua_State *L, int idx) /* {{{ */ { - if (idx < 0) - idx += lua_gettop(L) + 1; - - /* Copy the thread pointer */ - lua_pushvalue(L, idx); /* +1 = 3 */ - if (!lua_isthread(L, -1)) { - lua_pop(L, 3); /* -3 = 0 */ + if (!lua_isthread(L, idx)) { return -1; } + /* Copy the thread pointer */ + lua_pushvalue(L, idx); + luaL_ref(L, LUA_REGISTRYINDEX); - lua_pop(L, 1); /* -1 = 0 */ return 0; } /* }}} int clua_store_thread */