From: Remi Gacogne Date: Fri, 16 Dec 2016 13:39:46 +0000 (+0100) Subject: LuaWrapper: Use the correct index when storing a function X-Git-Tag: rec-4.0.5-rc1~18^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1e7a64574a4cd8ceed619ecc878f3976a0780067;p=pdns LuaWrapper: Use the correct index when storing a function The LuaWrapper used to assume that the function was at the top of the stack, making it effectively impossible to have a callback function parameter anywhere else than as the last parameter. (cherry picked from commit 4ec1e17418d539cea7eb4fb5469e905684ca6457) --- diff --git a/ext/luawrapper/include/LuaContext.hpp b/ext/luawrapper/include/LuaContext.hpp index 2c4bb30e8..273effd78 100644 --- a/ext/luawrapper/include/LuaContext.hpp +++ b/ext/luawrapper/include/LuaContext.hpp @@ -1642,10 +1642,10 @@ private: // structure that will ensure that a certain is stored somewhere in the registry struct ValueInRegistry { // this constructor will clone and hold the value at the top of the stack in the registry - ValueInRegistry(lua_State* lua) : lua{lua} + ValueInRegistry(lua_State* lua, int index=-1) : lua{lua} { lua_pushlightuserdata(lua, this); - lua_pushvalue(lua, -2); + lua_pushvalue(lua, -1 + index); lua_settable(lua, LUA_REGISTRYINDEX); } @@ -1821,8 +1821,8 @@ private: private: friend LuaContext; - explicit LuaFunctionCaller(lua_State* state) : - valueHolder(std::make_shared(state)), + explicit LuaFunctionCaller(lua_State* state, int index) : + valueHolder(std::make_shared(state, index)), state(state) {} }; @@ -2521,7 +2521,7 @@ struct LuaContext::Reader