dimanche 19 juin 2016

Storing C++ lambdas as binary data


I'm currently attempting to extend sqrat (squirrel binding utility) to cater for binding lambdas to squirrel.

The issue I've got is that although the storing and recalling code can know about the lambda's signature (Here is the code to set up the function that will execute the lambda)

// Arg Count 0
template <class R, class Args, class Arity>
SQFUNCTION SqMemberLambdaFuncDetail(R result, 
                                    Args args,
                                    boost::mpl::integral_c<unsigned int, 1> arity)
{
    return &SqLambda<R>::template Func0<false>;
}

// Arg Count 1
template <class R, class Args, class Arity>
SQFUNCTION SqMemberLambdaFuncDetail(R result, 
                                    Args args, 
                                    boost::mpl::integral_c<unsigned int, 2> arity)
{
    return &SqLambda<R>::template Func1<boost::mpl::at_c<Args, 1>::type, 2, false>;
}

template <class F>
SQFUNCTION SqMemberLambdaFunc(F f)
{
    typedef boost::function_types::result_type<decltype(&F::operator())>::type result_t;
    typedef boost::function_types::function_arity< decltype(&F::operator())> arity_t;
    typedef boost::function_types::parameter_types< decltype(&F::operator())>::type args_t;
    result_t result;
    args_t args;
    arity_t arity;
    return SqMemberLambdaFuncDetail<result_t, args_t, arity_t>(result, args, arity);
}

The lambda itself needs to be stored in an anonymous form, as binary data, and I can't seem to find a way to do that.


Aucun commentaire:

Enregistrer un commentaire