I'm wanting to incorporate a luabind into one of my projects. To do so I need to provide a function which behaves similar to call_function (see below). This function uses some template magic (courtesy of Boost) that I'd appreciate some help with. This is the first time I've really come across template metaprogramming (is that what it's called?) and so I'm a little lost. Here's a few snippets I'd appreciate help with.
#define LUABIND_TUPLE_PARAMS(z, n, data) const A##n *
#define LUABIND_OPERATOR_PARAMS(z, n, data) const A##n & a##n
I'm not really sure what this preprocessor bit is up to, I don't even know what it's called so searching is a little difficult. A is a template type. If I remember correctly #a would insert the literal text of a, but what do the multiple # do? After this preprocessor stuff comes this.
template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type
call_function(lua_State* L, const char* name BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) )
{
typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t;
#if BOOST_PP_ITERATION() == 0
tuple_t args;
#else
tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a));
#endif
}
As you can see it makes heavy use of Boost. I've googled BOOST_PP_ITERATION but still can't really make out what it's doing. Could someone please explain to me, preferably in the context of this code, what the BOOST_PP stuff is doing, and how it manages to get the arguments into args.
My end goal is to define a call_function within my own code that will generate args which I can pass to an overload of call_function which I'll define. This means I can use the same calling convention, but can also apply some preprocessing before invoking luabind.
This question is quite specific in the way I've worded it, but I hope the concepts are general enough for it to be OK on here.