From 950899d96e05196ed08565f9ae4ccb2bda2854f5 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Tue, 14 Mar 2017 12:21:48 +0100 Subject: [PATCH] LuaWrapper: Don't shadow variables Fix shadowed variables reported by `-Wshadow`. commit a07410d771c9ea1f38d5df56d097ec3084d87d3c Author: Remi Gacogne Date: Mon Feb 20 11:21:55 2017 +0100 --- include/LuaContext.hpp | 92 +++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/include/LuaContext.hpp b/include/LuaContext.hpp index 3971401..9fe62a2 100644 --- a/include/LuaContext.hpp +++ b/include/LuaContext.hpp @@ -169,10 +169,10 @@ class LuaContext { class WrongTypeException : public std::runtime_error { public: - WrongTypeException(std::string luaType, const std::type_info& destination) : - std::runtime_error("Trying to cast a lua variable from \"" + luaType + "\" to \"" + destination.name() + "\""), - luaType(luaType), - destination(destination) + WrongTypeException(std::string luaType_, const std::type_info& destination_) : + std::runtime_error("Trying to cast a lua variable from \"" + luaType_ + "\" to \"" + destination_.name() + "\""), + luaType(luaType_), + destination(destination_) { } @@ -426,12 +426,12 @@ class LuaContext { * @tparam TVarType Type of the member * @param name Name of the member to register * @param readFunction Function of type "TVarType (const TObject&)" - * @param writeFunction Function of type "void (TObject&, const TVarType&)" + * @param writeFunction_ Function of type "void (TObject&, const TVarType&)" */ template - void registerMember(const std::string& name, TReadFunction readFunction, TWriteFunction writeFunction) + void registerMember(const std::string& name, TReadFunction readFunction, TWriteFunction writeFunction_) { - registerMemberImpl(name, std::move(readFunction), std::move(writeFunction)); + registerMemberImpl(name, std::move(readFunction), std::move(writeFunction_)); } /** @@ -440,13 +440,13 @@ class LuaContext { * @tparam TMemberType Pointer to member object representing the type * @param name Name of the member to register * @param readFunction Function of type "TVarType (const TObject&)" - * @param writeFunction Function of type "void (TObject&, const TVarType&)" + * @param writeFunction_ Function of type "void (TObject&, const TVarType&)" */ template - void registerMember(const std::string& name, TReadFunction readFunction, TWriteFunction writeFunction) + void registerMember(const std::string& name, TReadFunction readFunction, TWriteFunction writeFunction_) { static_assert(std::is_member_object_pointer::value, "registerMember must take a member object pointer type as template parameter"); - registerMemberImpl(tag{}, name, std::move(readFunction), std::move(writeFunction)); + registerMemberImpl(tag{}, name, std::move(readFunction), std::move(writeFunction_)); } /** @@ -483,12 +483,12 @@ class LuaContext { * @tparam TObject Type to register the member to * @tparam TVarType Type of the member * @param readFunction Function of type "TVarType (const TObject&, const std::string&)" - * @param writeFunction Function of type "void (TObject&, const std::string&, const TVarType&)" + * @param writeFunction_ Function of type "void (TObject&, const std::string&, const TVarType&)" */ template - void registerMember(TReadFunction readFunction, TWriteFunction writeFunction) + void registerMember(TReadFunction readFunction, TWriteFunction writeFunction_) { - registerMemberImpl(std::move(readFunction), std::move(writeFunction)); + registerMemberImpl(std::move(readFunction), std::move(writeFunction_)); } /** @@ -496,13 +496,13 @@ class LuaContext { * This is the version "registerMember(getter, setter)" * @tparam TMemberType Pointer to member object representing the type * @param readFunction Function of type "TVarType (const TObject&, const std::string&)" - * @param writeFunction Function of type "void (TObject&, const std::string&, const TVarType&)" + * @param writeFunction_ Function of type "void (TObject&, const std::string&, const TVarType&)" */ template - void registerMember(TReadFunction readFunction, TWriteFunction writeFunction) + void registerMember(TReadFunction readFunction, TWriteFunction writeFunction_) { static_assert(std::is_member_object_pointer::value, "registerMember must take a member object pointer type as template parameter"); - registerMemberImpl(tag{}, std::move(readFunction), std::move(writeFunction)); + registerMemberImpl(tag{}, std::move(readFunction), std::move(writeFunction_)); } /** @@ -680,7 +680,7 @@ class LuaContext { /* PUSH OBJECT */ /**************************************************/ struct PushedObject { - PushedObject(lua_State* state, int num = 1) : state(state), num(num) {} + PushedObject(lua_State* state_, int num_ = 1) : state(state_), num(num_) {} ~PushedObject() { assert(lua_gettop(state) >= num); if (num >= 1) lua_pop(state, num); } PushedObject& operator=(const PushedObject&) = delete; @@ -1132,29 +1132,29 @@ class LuaContext { } template - void registerMemberImpl(const std::string& name, TReadFunction readFunction, TWriteFunction writeFunction) + void registerMemberImpl(const std::string& name, TReadFunction readFunction, TWriteFunction writeFunction_) { registerMemberImpl(name, readFunction); - setTable(mState, Registry, &typeid(TObject), 4, name, [writeFunction](TObject& object, const TVarType& value) { - writeFunction(object, value); + setTable(mState, Registry, &typeid(TObject), 4, name, [writeFunction_](TObject& object, const TVarType& value) { + writeFunction_(object, value); }); - setTable(mState, Registry, &typeid(TObject*), 4, name, [writeFunction](TObject* object, const TVarType& value) { + setTable(mState, Registry, &typeid(TObject*), 4, name, [writeFunction_](TObject* object, const TVarType& value) { assert(object); - writeFunction(*object, value); + writeFunction_(*object, value); }); - setTable, TVarType)>(mState, Registry, &typeid(std::shared_ptr), 4, name, [writeFunction](std::shared_ptr object, const TVarType& value) { + setTable, TVarType)>(mState, Registry, &typeid(std::shared_ptr), 4, name, [writeFunction_](std::shared_ptr object, const TVarType& value) { assert(object); - writeFunction(*object, value); + writeFunction_(*object, value); }); } template - void registerMemberImpl(tag, const std::string& name, TReadFunction readFunction, TWriteFunction writeFunction) + void registerMemberImpl(tag, const std::string& name, TReadFunction readFunction, TWriteFunction writeFunction_) { - registerMemberImpl(name, std::move(readFunction), std::move(writeFunction)); + registerMemberImpl(name, std::move(readFunction), std::move(writeFunction_)); } template @@ -1198,29 +1198,29 @@ class LuaContext { } template - void registerMemberImpl(TReadFunction readFunction, TWriteFunction writeFunction) + void registerMemberImpl(TReadFunction readFunction, TWriteFunction writeFunction_) { registerMemberImpl(readFunction); - setTable(mState, Registry, &typeid(TObject), 5, [writeFunction](TObject& object, const std::string& name, const TVarType& value) { - writeFunction(object, name, value); + setTable(mState, Registry, &typeid(TObject), 5, [writeFunction_](TObject& object, const std::string& name, const TVarType& value) { + writeFunction_(object, name, value); }); - setTable(mState, Registry, &typeid(TObject*), 2, [writeFunction](TObject* object, const std::string& name, const TVarType& value) { + setTable(mState, Registry, &typeid(TObject*), 2, [writeFunction_](TObject* object, const std::string& name, const TVarType& value) { assert(object); - writeFunction(*object, name, value); + writeFunction_(*object, name, value); }); - setTable, std::string, TVarType)>(mState, Registry, &typeid(std::shared_ptr), 2, [writeFunction](const std::shared_ptr& object, const std::string& name, const TVarType& value) { + setTable, std::string, TVarType)>(mState, Registry, &typeid(std::shared_ptr), 2, [writeFunction_](const std::shared_ptr& object, const std::string& name, const TVarType& value) { assert(object); - writeFunction(*object, name, value); + writeFunction_(*object, name, value); }); } template - void registerMemberImpl(tag, TReadFunction readFunction, TWriteFunction writeFunction) + void registerMemberImpl(tag, TReadFunction readFunction, TWriteFunction writeFunction_) { - registerMemberImpl(std::move(readFunction), std::move(writeFunction)); + registerMemberImpl(std::move(readFunction), std::move(writeFunction_)); } template @@ -1639,7 +1639,7 @@ class LuaContext { // structure that will ensure that a certain value is stored somewhere in the registry struct ValueInRegistry { // this constructor will clone and hold the value at the specified index (or by default at the top of the stack) in the registry - ValueInRegistry(lua_State* lua, int index=-1) : lua{lua} + ValueInRegistry(lua_State* lua_, int index=-1) : lua{lua_} { lua_pushlightuserdata(lua, this); lua_pushvalue(lua, -1 + index); @@ -1818,9 +1818,9 @@ class LuaContext::LuaFunctionCaller private: friend LuaContext; - explicit LuaFunctionCaller(lua_State* state, int index) : - valueHolder(std::make_shared(state, index)), - state(state) + explicit LuaFunctionCaller(lua_State* state_, int index) : + valueHolder(std::make_shared(state_, index)), + state(state_) {} }; @@ -2139,11 +2139,11 @@ struct LuaContext::Pusher // since "fn" doesn't need to be destroyed, we simply push it on the stack // this is the cfunction that is the callback - const auto function = [](lua_State* state) -> int + const auto function = [](lua_State* state_) -> int { // the function object is an upvalue - const auto toCall = static_cast(lua_touserdata(state, lua_upvalueindex(1))); - return callback(state, toCall, lua_gettop(state)).release(); + const auto toCall = static_cast(lua_touserdata(state_, lua_upvalueindex(1))); + return callback(state_, toCall, lua_gettop(state_)).release(); }; // we copy the function object onto the stack @@ -2163,11 +2163,11 @@ struct LuaContext::Pusher // since "fn" doesn't need to be destroyed, we simply push it on the stack // this is the cfunction that is the callback - const auto function = [](lua_State* state) -> int + const auto function = [](lua_State* state_) -> int { // the function object is an upvalue - const auto toCall = reinterpret_cast(lua_touserdata(state, lua_upvalueindex(1))); - return callback(state, toCall, lua_gettop(state)).release(); + const auto toCall = reinterpret_cast(lua_touserdata(state_, lua_upvalueindex(1))); + return callback(state_, toCall, lua_gettop(state_)).release(); }; // we copy the function object onto the stack @@ -2320,7 +2320,7 @@ struct LuaContext::Pusher> obj = Pusher::type>::push(state, std::move(value)); } - VariantWriter(lua_State* state, PushedObject& obj) : state(state), obj(obj) {} + VariantWriter(lua_State* state_, PushedObject& obj_) : state(state_), obj(obj_) {} lua_State* state; PushedObject& obj; };