lua plugin: don't elements from stack in `clua_store_thread`.
authorPavel Rochnyack <pavel2000@ngs.ru>
Wed, 1 May 2019 09:10:35 +0000 (16:10 +0700)
committerPavel Rochnyack <pavel2000@ngs.ru>
Wed, 1 May 2019 09:10:35 +0000 (16:10 +0700)
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.

src/lua.c

index a0364d7..8dc78d0 100644 (file)
--- 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) /* {{{ */
 {
  * 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;
   }
 
     return -1;
   }
 
+  /* Copy the thread pointer */
+  lua_pushvalue(L, idx);
+
   luaL_ref(L, LUA_REGISTRYINDEX);
   luaL_ref(L, LUA_REGISTRYINDEX);
-  lua_pop(L, 1); /* -1 = 0 */
   return 0;
 } /* }}} int clua_store_thread */
 
   return 0;
 } /* }}} int clua_store_thread */