Skip to content

Commit

Permalink
pass one tag for all remaining parameter types
Browse files Browse the repository at this point in the history
make tag a variadic template and use it to pass multiple types in one go
to readIntoFunction.

This fixes an Internal Compiler Error on VS 2015.2:
- fixes #7
- closes #8
  • Loading branch information
ThePhD authored and stbuehler committed Mar 23, 2017
1 parent 670a4fc commit 6ee3b8e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions include/LuaContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ class LuaContext {
/* MISC */
/**************************************************/
// type used as a tag
template<typename T>
template<typename... Tn>
struct tag {};

// tag for "the registry"
Expand Down Expand Up @@ -1596,29 +1596,29 @@ class LuaContext {
* This functions reads multiple values starting at "index" and passes them to the callback
*/
template<typename TRetValue, typename TCallback>
static auto readIntoFunction(lua_State* /*state*/, tag<TRetValue>, TCallback&& callback, int /*index*/)
static auto readIntoFunction(lua_State* /*state*/, tag<TRetValue>, TCallback&& callback, int /*index*/, tag<>)
-> TRetValue
{
return callback();
}
template<typename TRetValue, typename TCallback, typename TFirstType, typename... TTypes>
static auto readIntoFunction(lua_State* state, tag<TRetValue> retValueTag, TCallback&& callback, int index, tag<TFirstType>, tag<TTypes>... othersTags)
static auto readIntoFunction(lua_State* state, tag<TRetValue> retValueTag, TCallback&& callback, int index, tag<TFirstType, TTypes...>)
-> typename std::enable_if<IsOptional<TFirstType>::value, TRetValue>::type
{
if (index >= 0) {
Binder<TCallback, const TFirstType&> binder{ callback, {} };
return readIntoFunction(state, retValueTag, binder, index + 1, othersTags...);
return readIntoFunction(state, retValueTag, binder, index + 1, tag<TTypes...>());
}

const auto& firstElem = Reader<typename std::decay<TFirstType>::type>::read(state, index);
if (!firstElem)
throw WrongTypeException(lua_typename(state, lua_type(state, index)), typeid(TFirstType));

Binder<TCallback, const TFirstType&> binder{ callback, *firstElem };
return readIntoFunction(state, retValueTag, binder, index + 1, othersTags...);
return readIntoFunction(state, retValueTag, binder, index + 1, tag<TTypes...>());
}
template<typename TRetValue, typename TCallback, typename TFirstType, typename... TTypes>
static auto readIntoFunction(lua_State* state, tag<TRetValue> retValueTag, TCallback&& callback, int index, tag<TFirstType>, tag<TTypes>... othersTags)
static auto readIntoFunction(lua_State* state, tag<TRetValue> retValueTag, TCallback&& callback, int index, tag<TFirstType, TTypes...>)
-> typename std::enable_if<!IsOptional<TFirstType>::value, TRetValue>::type
{
if (index >= 0)
Expand All @@ -1629,7 +1629,7 @@ class LuaContext {
throw WrongTypeException(lua_typename(state, lua_type(state, index)), typeid(TFirstType));

Binder<TCallback, const TFirstType&> binder{ callback, *firstElem };
return readIntoFunction(state, retValueTag, binder, index + 1, othersTags...);
return readIntoFunction(state, retValueTag, binder, index + 1, tag<TTypes...>());
}


Expand Down Expand Up @@ -2239,14 +2239,14 @@ struct LuaContext::Pusher<TReturnType (TParameters...)>
// pushing the result on the stack and returning number of pushed elements
typedef Pusher<typename std::decay<TReturnType>::type>
P;
return P::push(state, readIntoFunction(state, tag<TReturnType>{}, toCall, -argumentsCount, tag<TParameters>{}...));
return P::push(state, readIntoFunction(state, tag<TReturnType>{}, toCall, -argumentsCount, tag<TParameters...>{}));
}

template<typename TFunctionObject>
static auto callback2(lua_State* state, TFunctionObject&& toCall, int argumentsCount)
-> typename std::enable_if<std::is_void<TReturnType>::value && !std::is_void<TFunctionObject>::value, PushedObject>::type
{
readIntoFunction(state, tag<TReturnType>{}, toCall, -argumentsCount, tag<TParameters>{}...);
readIntoFunction(state, tag<TReturnType>{}, toCall, -argumentsCount, tag<TParameters...>{});
return PushedObject{state, 0};
}
};
Expand Down

0 comments on commit 6ee3b8e

Please sign in to comment.