Sha256: dbab04599c5aed3037bd3d1e4ac126ed8f1f4ba617b462968c0b455f9043a7a4

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

#ifndef Rice__detail__ruby_function__hpp_
#define Rice__detail__ruby_function__hpp_

#include "ruby.hpp"

namespace Rice::detail
{
  /* This is functor class that wraps calls to a Ruby C API method. It is needed because
     rb_protect only supports calling methods that take one argument. Thus 
     we invoke rb_protect telling it to invoke Ruby_Function::call with an 
     instance of a Ruby_Function. That instance then in turn calls the original
     Ruby method passing along its required arguments. */

  template<typename Function_T, typename Return_T, typename...Arg_Ts>
  class RubyFunction
  {
  public:
    RubyFunction(Function_T func, const Arg_Ts&... args);
    Return_T operator()();

  private:
    Function_T func_;
    std::tuple<Arg_Ts...> args_;
  };

  template<typename Return_T, typename ...Arg_Ts>
  Return_T protect(Return_T(*func)(Arg_Ts...), Arg_Ts...args);
}

namespace Rice
{
  template<typename Return_T, typename ...Arg_Ts>
  [[deprecated("Please use detail::protect")]]
  Return_T protect(Return_T(*func)(Arg_Ts...), Arg_Ts...args);
}

#include "RubyFunction.ipp"

#endif // Rice__detail__ruby_function__hpp_

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rice-4.0.4 rice/detail/RubyFunction.hpp
rice-4.0.3 rice/detail/RubyFunction.hpp
rice-4.0.2 rice/detail/RubyFunction.hpp
rice-4.0.1 rice/detail/RubyFunction.hpp
rice-4.0.0 rice/detail/RubyFunction.hpp