From 4ec1e17418d539cea7eb4fb5469e905684ca6457 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 16 Dec 2016 14:39:46 +0100 Subject: [PATCH] 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. --- ext/luawrapper/include/LuaContext.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/luawrapper/include/LuaContext.hpp b/ext/luawrapper/include/LuaContext.hpp index e9627d689..b31e9cd39 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