Skip to content

Commit

Permalink
Merge pull request tomaka#31 from PowerDNS/no-shadow
Browse files Browse the repository at this point in the history
Upstream from PowerDNS: don't shadow variables
  • Loading branch information
Habbie authored Mar 24, 2017
2 parents ed127fc + 950899d commit 2b1eade
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions include/LuaContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
{
}

Expand Down Expand Up @@ -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<typename TObject, typename TVarType, typename TReadFunction, typename TWriteFunction>
void registerMember(const std::string& name, TReadFunction readFunction, TWriteFunction writeFunction)
void registerMember(const std::string& name, TReadFunction readFunction, TWriteFunction writeFunction_)
{
registerMemberImpl<TObject,TVarType>(name, std::move(readFunction), std::move(writeFunction));
registerMemberImpl<TObject,TVarType>(name, std::move(readFunction), std::move(writeFunction_));
}

/**
Expand All @@ -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<typename TMemberType, typename TReadFunction, typename TWriteFunction>
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<TMemberType>::value, "registerMember must take a member object pointer type as template parameter");
registerMemberImpl(tag<TMemberType>{}, name, std::move(readFunction), std::move(writeFunction));
registerMemberImpl(tag<TMemberType>{}, name, std::move(readFunction), std::move(writeFunction_));
}

/**
Expand Down Expand Up @@ -483,26 +483,26 @@ 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<typename TObject, typename TVarType, typename TReadFunction, typename TWriteFunction>
void registerMember(TReadFunction readFunction, TWriteFunction writeFunction)
void registerMember(TReadFunction readFunction, TWriteFunction writeFunction_)
{
registerMemberImpl<TObject,TVarType>(std::move(readFunction), std::move(writeFunction));
registerMemberImpl<TObject,TVarType>(std::move(readFunction), std::move(writeFunction_));
}

/**
* Registers a dynamic member variable
* This is the version "registerMember<int (Foo::*)>(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<typename TMemberType, typename TReadFunction, typename TWriteFunction>
void registerMember(TReadFunction readFunction, TWriteFunction writeFunction)
void registerMember(TReadFunction readFunction, TWriteFunction writeFunction_)
{
static_assert(std::is_member_object_pointer<TMemberType>::value, "registerMember must take a member object pointer type as template parameter");
registerMemberImpl(tag<TMemberType>{}, std::move(readFunction), std::move(writeFunction));
registerMemberImpl(tag<TMemberType>{}, std::move(readFunction), std::move(writeFunction_));
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1132,29 +1132,29 @@ class LuaContext {
}

template<typename TObject, typename TVarType, typename TReadFunction, typename TWriteFunction>
void registerMemberImpl(const std::string& name, TReadFunction readFunction, TWriteFunction writeFunction)
void registerMemberImpl(const std::string& name, TReadFunction readFunction, TWriteFunction writeFunction_)
{
registerMemberImpl<TObject,TVarType>(name, readFunction);

setTable<void (TObject&, TVarType)>(mState, Registry, &typeid(TObject), 4, name, [writeFunction](TObject& object, const TVarType& value) {
writeFunction(object, value);
setTable<void (TObject&, TVarType)>(mState, Registry, &typeid(TObject), 4, name, [writeFunction_](TObject& object, const TVarType& value) {
writeFunction_(object, value);
});

setTable<void (TObject*, TVarType)>(mState, Registry, &typeid(TObject*), 4, name, [writeFunction](TObject* object, const TVarType& value) {
setTable<void (TObject*, TVarType)>(mState, Registry, &typeid(TObject*), 4, name, [writeFunction_](TObject* object, const TVarType& value) {
assert(object);
writeFunction(*object, value);
writeFunction_(*object, value);
});

setTable<void (std::shared_ptr<TObject>, TVarType)>(mState, Registry, &typeid(std::shared_ptr<TObject>), 4, name, [writeFunction](std::shared_ptr<TObject> object, const TVarType& value) {
setTable<void (std::shared_ptr<TObject>, TVarType)>(mState, Registry, &typeid(std::shared_ptr<TObject>), 4, name, [writeFunction_](std::shared_ptr<TObject> object, const TVarType& value) {
assert(object);
writeFunction(*object, value);
writeFunction_(*object, value);
});
}

template<typename TObject, typename TVarType, typename TReadFunction, typename TWriteFunction>
void registerMemberImpl(tag<TVarType (TObject::*)>, const std::string& name, TReadFunction readFunction, TWriteFunction writeFunction)
void registerMemberImpl(tag<TVarType (TObject::*)>, const std::string& name, TReadFunction readFunction, TWriteFunction writeFunction_)
{
registerMemberImpl<TObject,TVarType>(name, std::move(readFunction), std::move(writeFunction));
registerMemberImpl<TObject,TVarType>(name, std::move(readFunction), std::move(writeFunction_));
}

template<typename TObject, typename TVarType, typename TReadFunction>
Expand Down Expand Up @@ -1198,29 +1198,29 @@ class LuaContext {
}

template<typename TObject, typename TVarType, typename TReadFunction, typename TWriteFunction>
void registerMemberImpl(TReadFunction readFunction, TWriteFunction writeFunction)
void registerMemberImpl(TReadFunction readFunction, TWriteFunction writeFunction_)
{
registerMemberImpl<TObject,TVarType>(readFunction);

setTable<void (TObject&, std::string, TVarType)>(mState, Registry, &typeid(TObject), 5, [writeFunction](TObject& object, const std::string& name, const TVarType& value) {
writeFunction(object, name, value);
setTable<void (TObject&, std::string, TVarType)>(mState, Registry, &typeid(TObject), 5, [writeFunction_](TObject& object, const std::string& name, const TVarType& value) {
writeFunction_(object, name, value);
});

setTable<void (TObject*, std::string, TVarType)>(mState, Registry, &typeid(TObject*), 2, [writeFunction](TObject* object, const std::string& name, const TVarType& value) {
setTable<void (TObject*, std::string, TVarType)>(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<void (std::shared_ptr<TObject>, std::string, TVarType)>(mState, Registry, &typeid(std::shared_ptr<TObject>), 2, [writeFunction](const std::shared_ptr<TObject>& object, const std::string& name, const TVarType& value) {
setTable<void (std::shared_ptr<TObject>, std::string, TVarType)>(mState, Registry, &typeid(std::shared_ptr<TObject>), 2, [writeFunction_](const std::shared_ptr<TObject>& object, const std::string& name, const TVarType& value) {
assert(object);
writeFunction(*object, name, value);
writeFunction_(*object, name, value);
});
}

template<typename TObject, typename TVarType, typename TReadFunction, typename TWriteFunction>
void registerMemberImpl(tag<TVarType (TObject::*)>, TReadFunction readFunction, TWriteFunction writeFunction)
void registerMemberImpl(tag<TVarType (TObject::*)>, TReadFunction readFunction, TWriteFunction writeFunction_)
{
registerMemberImpl<TObject,TVarType>(std::move(readFunction), std::move(writeFunction));
registerMemberImpl<TObject,TVarType>(std::move(readFunction), std::move(writeFunction_));
}

template<typename TObject, typename TVarType, typename TReadFunction>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1818,9 +1818,9 @@ class LuaContext::LuaFunctionCaller<TRetValue (TParams...)>

private:
friend LuaContext;
explicit LuaFunctionCaller(lua_State* state, int index) :
valueHolder(std::make_shared<ValueInRegistry>(state, index)),
state(state)
explicit LuaFunctionCaller(lua_State* state_, int index) :
valueHolder(std::make_shared<ValueInRegistry>(state_, index)),
state(state_)
{}
};

Expand Down Expand Up @@ -2139,11 +2139,11 @@ struct LuaContext::Pusher<TReturnType (TParameters...)>
// 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<TFunctionObject*>(lua_touserdata(state, lua_upvalueindex(1)));
return callback(state, toCall, lua_gettop(state)).release();
const auto toCall = static_cast<TFunctionObject*>(lua_touserdata(state_, lua_upvalueindex(1)));
return callback(state_, toCall, lua_gettop(state_)).release();
};

// we copy the function object onto the stack
Expand All @@ -2163,11 +2163,11 @@ struct LuaContext::Pusher<TReturnType (TParameters...)>
// 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<TReturnType (*)(TParameters...)>(lua_touserdata(state, lua_upvalueindex(1)));
return callback(state, toCall, lua_gettop(state)).release();
const auto toCall = reinterpret_cast<TReturnType (*)(TParameters...)>(lua_touserdata(state_, lua_upvalueindex(1)));
return callback(state_, toCall, lua_gettop(state_)).release();
};

// we copy the function object onto the stack
Expand Down Expand Up @@ -2320,7 +2320,7 @@ struct LuaContext::Pusher<boost::variant<TTypes...>>
obj = Pusher<typename std::decay<TType>::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;
};
Expand Down

0 comments on commit 2b1eade

Please sign in to comment.