rice 4.7.1 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -1
  3. data/CMakeLists.txt +14 -22
  4. data/CMakePresets.json +203 -75
  5. data/FindRuby.cmake +358 -123
  6. data/bin/rice-doc.rb +56 -141
  7. data/include/rice/api.hpp +248 -0
  8. data/include/rice/rice.hpp +2237 -1657
  9. data/include/rice/stl.hpp +346 -443
  10. data/lib/rice/doc/config.rb +70 -0
  11. data/lib/rice/doc/cpp_reference.rb +1 -4
  12. data/lib/rice/doc/mkdocs.rb +58 -20
  13. data/lib/rice/doc/rice.rb +20 -0
  14. data/lib/rice/doc.rb +1 -0
  15. data/lib/rice/make_rice_headers.rb +7 -0
  16. data/lib/rice/native_registry.rb +2 -2
  17. data/lib/rice/rbs.rb +2 -2
  18. data/lib/rice/version.rb +1 -1
  19. data/lib/rubygems_plugin.rb +12 -9
  20. data/rice/Arg.hpp +12 -6
  21. data/rice/Arg.ipp +14 -7
  22. data/rice/Buffer.ipp +44 -40
  23. data/rice/Callback.hpp +1 -1
  24. data/rice/Callback.ipp +2 -7
  25. data/rice/Constructor.hpp +1 -1
  26. data/rice/Constructor.ipp +11 -11
  27. data/rice/Data_Object.ipp +15 -15
  28. data/rice/Data_Type.hpp +9 -10
  29. data/rice/Data_Type.ipp +22 -25
  30. data/rice/Director.hpp +1 -0
  31. data/rice/Enum.ipp +58 -39
  32. data/rice/Exception.hpp +4 -4
  33. data/rice/Exception.ipp +7 -7
  34. data/rice/NoGVL.hpp +13 -0
  35. data/rice/Reference.hpp +56 -0
  36. data/rice/Reference.ipp +96 -0
  37. data/rice/Return.hpp +4 -1
  38. data/rice/Return.ipp +0 -6
  39. data/rice/cpp_api/Array.hpp +41 -4
  40. data/rice/cpp_api/Array.ipp +105 -9
  41. data/rice/cpp_api/Class.hpp +2 -2
  42. data/rice/cpp_api/Class.ipp +4 -4
  43. data/rice/cpp_api/Hash.ipp +7 -4
  44. data/rice/cpp_api/Module.hpp +4 -4
  45. data/rice/cpp_api/Module.ipp +12 -10
  46. data/rice/cpp_api/Object.hpp +4 -4
  47. data/rice/cpp_api/Object.ipp +15 -12
  48. data/rice/cpp_api/String.hpp +2 -2
  49. data/rice/cpp_api/String.ipp +11 -8
  50. data/rice/cpp_api/Symbol.ipp +7 -7
  51. data/rice/cpp_api/shared_methods.hpp +5 -9
  52. data/rice/detail/InstanceRegistry.hpp +0 -2
  53. data/rice/detail/Native.hpp +31 -21
  54. data/rice/detail/Native.ipp +282 -130
  55. data/rice/detail/NativeAttributeGet.hpp +5 -7
  56. data/rice/detail/NativeAttributeGet.ipp +26 -26
  57. data/rice/detail/NativeAttributeSet.hpp +2 -4
  58. data/rice/detail/NativeAttributeSet.ipp +20 -16
  59. data/rice/detail/NativeCallback.hpp +77 -0
  60. data/rice/detail/NativeCallback.ipp +280 -0
  61. data/rice/detail/NativeFunction.hpp +11 -21
  62. data/rice/detail/NativeFunction.ipp +58 -119
  63. data/rice/detail/NativeInvoker.hpp +4 -4
  64. data/rice/detail/NativeInvoker.ipp +7 -7
  65. data/rice/detail/NativeIterator.hpp +2 -4
  66. data/rice/detail/NativeIterator.ipp +18 -14
  67. data/rice/detail/NativeMethod.hpp +10 -20
  68. data/rice/detail/NativeMethod.ipp +54 -114
  69. data/rice/detail/NativeProc.hpp +5 -7
  70. data/rice/detail/NativeProc.ipp +39 -28
  71. data/rice/detail/NativeRegistry.hpp +0 -1
  72. data/rice/detail/Parameter.hpp +15 -8
  73. data/rice/detail/Parameter.ipp +102 -43
  74. data/rice/detail/Proc.ipp +14 -28
  75. data/rice/detail/RubyType.ipp +2 -53
  76. data/rice/detail/Type.hpp +23 -7
  77. data/rice/detail/Type.ipp +73 -93
  78. data/rice/detail/TypeRegistry.ipp +5 -4
  79. data/rice/detail/Wrapper.hpp +1 -1
  80. data/rice/detail/Wrapper.ipp +18 -10
  81. data/rice/detail/from_ruby.hpp +8 -6
  82. data/rice/detail/from_ruby.ipp +306 -173
  83. data/rice/detail/ruby.hpp +23 -0
  84. data/rice/libc/file.hpp +4 -4
  85. data/rice/rice.hpp +6 -8
  86. data/rice/rice_api/Native.ipp +5 -1
  87. data/rice/rice_api/Parameter.ipp +1 -1
  88. data/rice/ruby_mark.hpp +2 -1
  89. data/rice/stl/complex.ipp +12 -8
  90. data/rice/stl/map.ipp +27 -22
  91. data/rice/stl/monostate.ipp +16 -12
  92. data/rice/stl/multimap.hpp +0 -2
  93. data/rice/stl/multimap.ipp +27 -22
  94. data/rice/stl/optional.ipp +27 -11
  95. data/rice/stl/pair.ipp +5 -5
  96. data/rice/stl/reference_wrapper.ipp +5 -4
  97. data/rice/stl/set.ipp +16 -16
  98. data/rice/stl/shared_ptr.hpp +0 -16
  99. data/rice/stl/shared_ptr.ipp +34 -190
  100. data/rice/stl/string.ipp +18 -18
  101. data/rice/stl/string_view.ipp +1 -1
  102. data/rice/stl/tuple.ipp +15 -36
  103. data/rice/stl/unique_ptr.ipp +18 -8
  104. data/rice/stl/unordered_map.ipp +20 -15
  105. data/rice/stl/variant.ipp +37 -21
  106. data/rice/stl/vector.ipp +41 -36
  107. data/rice/traits/function_traits.hpp +19 -19
  108. data/rice/traits/method_traits.hpp +4 -4
  109. data/rice/traits/rice_traits.hpp +162 -39
  110. data/rice.gemspec +1 -3
  111. data/test/test_Array.cpp +261 -3
  112. data/test/test_Attribute.cpp +6 -3
  113. data/test/test_Buffer.cpp +6 -42
  114. data/test/test_Callback.cpp +77 -23
  115. data/test/test_Data_Object.cpp +1 -1
  116. data/test/test_Data_Type.cpp +21 -22
  117. data/test/test_Director.cpp +2 -4
  118. data/test/test_Enum.cpp +34 -5
  119. data/test/test_File.cpp +9 -5
  120. data/test/test_From_Ruby.cpp +4 -3
  121. data/test/test_GVL.cpp +3 -3
  122. data/test/test_Hash.cpp +1 -1
  123. data/test/test_Iterator.cpp +54 -22
  124. data/test/test_Keep_Alive.cpp +1 -1
  125. data/test/test_Keep_Alive_No_Wrapper.cpp +1 -1
  126. data/test/test_Module.cpp +5 -5
  127. data/test/test_Overloads.cpp +345 -48
  128. data/test/test_Proc.cpp +54 -0
  129. data/test/test_Reference.cpp +181 -0
  130. data/test/test_Self.cpp +2 -2
  131. data/test/test_Stl_Set.cpp +6 -6
  132. data/test/test_Stl_SharedPtr.cpp +54 -30
  133. data/test/test_Stl_String_View.cpp +4 -2
  134. data/test/test_Stl_Tuple.cpp +1 -1
  135. data/test/test_Stl_Variant.cpp +6 -14
  136. data/test/test_Stl_Vector.cpp +61 -30
  137. data/test/test_String.cpp +4 -2
  138. data/test/test_Struct.cpp +1 -1
  139. data/test/test_Symbol.cpp +1 -1
  140. data/test/test_To_Ruby.cpp +1 -0
  141. data/test/test_Type.cpp +36 -35
  142. data/test/test_global_functions.cpp +1 -1
  143. data/test/unittest.cpp +1 -1
  144. data/test/unittest.hpp +5 -5
  145. metadata +10 -10
  146. data/rice/Function.hpp +0 -17
  147. data/rice/Function.ipp +0 -13
  148. data/rice/detail/MethodInfo.hpp +0 -48
  149. data/rice/detail/MethodInfo.ipp +0 -99
  150. data/rice/detail/NativeCallbackFFI.hpp +0 -55
  151. data/rice/detail/NativeCallbackFFI.ipp +0 -152
  152. data/rice/detail/NativeCallbackSimple.hpp +0 -30
  153. data/rice/detail/NativeCallbackSimple.ipp +0 -29
@@ -234,7 +234,7 @@ namespace Rice::detail
234
234
  public:
235
235
  To_Ruby() = default;
236
236
 
237
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
237
+ explicit To_Ruby(Arg* arg) : arg_(arg)
238
238
  {
239
239
  }
240
240
 
@@ -244,7 +244,7 @@ namespace Rice::detail
244
244
  }
245
245
 
246
246
  private:
247
- Return* returnInfo_ = nullptr;
247
+ Arg* arg_ = nullptr;
248
248
  };
249
249
 
250
250
  template<>
@@ -253,11 +253,11 @@ namespace Rice::detail
253
253
  public:
254
254
  From_Ruby() = default;
255
255
 
256
- explicit From_Ruby(Arg* arg)
256
+ explicit From_Ruby(Arg* arg) : arg_(arg)
257
257
  {
258
258
  }
259
259
 
260
- Convertible is_convertible(VALUE value)
260
+ double is_convertible(VALUE value)
261
261
  {
262
262
  switch (rb_type(value))
263
263
  {
@@ -273,5 +273,8 @@ namespace Rice::detail
273
273
  {
274
274
  return Hash(value);
275
275
  }
276
+
277
+ private:
278
+ Arg* arg_ = nullptr;
276
279
  };
277
280
  }
@@ -49,11 +49,11 @@ namespace Rice
49
49
 
50
50
  #include "shared_methods.hpp"
51
51
  protected:
52
- template<typename Function_T>
53
- void wrap_native_function(VALUE klass, std::string name, Function_T&& function, MethodInfo* methodInfo);
52
+ template<typename Function_T, typename ...Arg_Ts>
53
+ void wrap_native_function(VALUE klass, std::string name, Function_T&& function, const Arg_Ts&...args);
54
54
 
55
- template<typename Class_T = VALUE, typename Method_T>
56
- void wrap_native_method(VALUE klass, std::string name, Method_T&& method, MethodInfo* methodInfo);
55
+ template<typename Class_T = VALUE, typename Method_T, typename ...Arg_Ts>
56
+ void wrap_native_method(VALUE klass, std::string name, Method_T&& method, const Arg_Ts&...args);
57
57
  };
58
58
 
59
59
  //! Define a new module in the namespace given by module.
@@ -32,16 +32,18 @@ namespace Rice
32
32
  this->set_value(result);
33
33
  }
34
34
 
35
- template<typename Function_T>
36
- inline void Module::wrap_native_function(VALUE klass, std::string name, Function_T&& function, MethodInfo* methodInfo)
35
+ template<typename Function_T, typename ...Arg_Ts>
36
+ inline void Module::wrap_native_function(VALUE klass, std::string name, Function_T&& function, const Arg_Ts&...args)
37
37
  {
38
- detail::NativeFunction<Function_T>::define(klass, name, std::forward<Function_T>(function), methodInfo);
38
+ constexpr bool isNoGVL = detail::tuple_element_index_v<std::tuple<Arg_Ts...>, NoGVL> < (sizeof...(Arg_Ts));
39
+ detail::NativeFunction<Function_T, isNoGVL>::define(klass, name, std::forward<Function_T>(function), args...);
39
40
  }
40
41
 
41
- template<typename Class_T, typename Method_T>
42
- inline void Module::wrap_native_method(VALUE klass, std::string name, Method_T&& method, MethodInfo* methodInfo)
42
+ template<typename Class_T, typename Method_T, typename ...Arg_Ts>
43
+ inline void Module::wrap_native_method(VALUE klass, std::string name, Method_T&& method, const Arg_Ts&...args)
43
44
  {
44
- detail::NativeMethod<Class_T, Method_T>::define(klass, name, std::forward<Method_T>(method), methodInfo);
45
+ constexpr bool isNoGVL = detail::tuple_element_index_v<std::tuple<Arg_Ts...>, NoGVL> < (sizeof...(Arg_Ts));
46
+ detail::NativeMethod<Class_T, Method_T, isNoGVL>::define(klass, name, std::forward<Method_T>(method), args...);
45
47
  }
46
48
 
47
49
  inline Module define_module_under(Object parent, char const* name)
@@ -94,7 +96,7 @@ namespace Rice::detail
94
96
  public:
95
97
  To_Ruby() = default;
96
98
 
97
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
99
+ explicit To_Ruby(Arg* arg) : arg_(arg)
98
100
  {
99
101
  }
100
102
 
@@ -104,7 +106,7 @@ namespace Rice::detail
104
106
  }
105
107
 
106
108
  private:
107
- Return* returnInfo_ = nullptr;
109
+ Arg* arg_ = nullptr;
108
110
  };
109
111
 
110
112
 
@@ -114,7 +116,7 @@ namespace Rice::detail
114
116
  public:
115
117
  To_Ruby() = default;
116
118
 
117
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
119
+ explicit To_Ruby(Arg* arg) : arg_(arg)
118
120
  {
119
121
  }
120
122
 
@@ -124,7 +126,7 @@ namespace Rice::detail
124
126
  }
125
127
 
126
128
  private:
127
- Return* returnInfo_ = nullptr;
129
+ Arg* arg_ = nullptr;
128
130
  };
129
131
 
130
132
  template<>
@@ -181,8 +181,8 @@ namespace Rice
181
181
  * float ret = x.call<float>("foo", z, 42);
182
182
  * \endcode
183
183
  */
184
- template<typename ...Arg_Ts>
185
- Object call(Identifier id, Arg_Ts... args) const;
184
+ template<typename ...Parameter_Ts>
185
+ Object call(Identifier id, Parameter_Ts... args) const;
186
186
 
187
187
  //! Call the Ruby method specified by 'id' on object 'obj'.
188
188
  /*! Pass in arguments (arg1, arg2, ...). The arguments will be converted to
@@ -204,8 +204,8 @@ namespace Rice
204
204
  * float ret = x.call_kw<float>("foo", kw);
205
205
  * \endcode
206
206
  */
207
- template<typename ...Arg_Ts>
208
- Object call_kw(Identifier id, Arg_Ts... args) const;
207
+ template<typename ...Parameter_Ts>
208
+ Object call_kw(Identifier id, Parameter_Ts... args) const;
209
209
 
210
210
  //! Vectorized call.
211
211
  /*! Calls the method identified by id with the list of arguments
@@ -27,8 +27,8 @@ namespace Rice
27
27
  return *this;
28
28
  }
29
29
 
30
- template<typename ...Arg_Ts>
31
- inline Object Object::call(Identifier id, Arg_Ts... args) const
30
+ template<typename ...Parameter_Ts>
31
+ inline Object Object::call(Identifier id, Parameter_Ts... args) const
32
32
  {
33
33
  /* IMPORTANT - We store VALUEs in an array that is a local variable.
34
34
  That allows the Ruby garbage collector to find them when scanning
@@ -37,15 +37,15 @@ namespace Rice
37
37
  to the destination method resulting in a segmentation fault. This is
38
38
  easy to duplicate by setting GC.stress to true and calling a constructor
39
39
  that takes multiple values like a std::pair wrapper. */
40
- std::array<VALUE, sizeof...(Arg_Ts)> values = { detail::To_Ruby<detail::remove_cv_recursive_t<Arg_Ts>>().convert(std::forward<Arg_Ts>(args))... };
40
+ std::array<VALUE, sizeof...(Parameter_Ts)> values = { detail::To_Ruby<detail::remove_cv_recursive_t<Parameter_Ts>>().convert(std::forward<Parameter_Ts>(args))... };
41
41
  return detail::protect(rb_funcallv, value(), id.id(), (int)values.size(), (const VALUE*)values.data());
42
42
  }
43
43
 
44
- template<typename ...Arg_Ts>
45
- inline Object Object::call_kw(Identifier id, Arg_Ts... args) const
44
+ template<typename ...Parameter_Ts>
45
+ inline Object Object::call_kw(Identifier id, Parameter_Ts... args) const
46
46
  {
47
47
  /* IMPORTANT - See call() above */
48
- std::array<VALUE, sizeof...(Arg_Ts)> values = { detail::To_Ruby<detail::remove_cv_recursive_t<Arg_Ts>>().convert(args)... };
48
+ std::array<VALUE, sizeof...(Parameter_Ts)> values = { detail::To_Ruby<detail::remove_cv_recursive_t<Parameter_Ts>>().convert(args)... };
49
49
  return detail::protect(rb_funcallv_kw, value(), id.id(), (int)values.size(), (const VALUE*)values.data(), RB_PASS_KEYWORDS);
50
50
  }
51
51
 
@@ -202,7 +202,7 @@ namespace Rice::detail
202
202
  public:
203
203
  To_Ruby() = default;
204
204
 
205
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
205
+ explicit To_Ruby(Arg* arg) : arg_(arg)
206
206
  {
207
207
  }
208
208
 
@@ -212,7 +212,7 @@ namespace Rice::detail
212
212
  }
213
213
 
214
214
  private:
215
- Return* returnInfo_ = nullptr;
215
+ Arg* arg_ = nullptr;
216
216
  };
217
217
 
218
218
  template<>
@@ -221,7 +221,7 @@ namespace Rice::detail
221
221
  public:
222
222
  To_Ruby() = default;
223
223
 
224
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
224
+ explicit To_Ruby(Arg* arg) : arg_(arg)
225
225
  {
226
226
  }
227
227
 
@@ -231,7 +231,7 @@ namespace Rice::detail
231
231
  }
232
232
 
233
233
  private:
234
- Return* returnInfo_ = nullptr;
234
+ Arg* arg_ = nullptr;
235
235
  };
236
236
 
237
237
  template<>
@@ -240,11 +240,11 @@ namespace Rice::detail
240
240
  public:
241
241
  From_Ruby() = default;
242
242
 
243
- explicit From_Ruby(Arg* arg)
243
+ explicit From_Ruby(Arg* arg) : arg_(arg)
244
244
  {
245
245
  }
246
246
 
247
- Convertible is_convertible(VALUE value)
247
+ double is_convertible(VALUE value)
248
248
  {
249
249
  switch (rb_type(value))
250
250
  {
@@ -260,5 +260,8 @@ namespace Rice::detail
260
260
  {
261
261
  return Object(value);
262
262
  }
263
+
264
+ private:
265
+ Arg* arg_ = nullptr;
263
266
  };
264
267
  }
@@ -38,8 +38,8 @@ namespace Rice
38
38
  String(std::string_view const& s);
39
39
 
40
40
  //! Format a string using printf-style formatting.
41
- template <typename... Arg_Ts>
42
- static inline String format(char const* fmt, Arg_Ts&&...args);
41
+ template <typename... Parameter_Ts>
42
+ static inline String format(char const* fmt, Parameter_Ts&&...args);
43
43
 
44
44
  //! Get the length of the String.
45
45
  /*! \return the length of the string.
@@ -28,16 +28,16 @@ namespace Rice
28
28
  {
29
29
  }
30
30
 
31
- template <typename... Arg_Ts>
32
- inline String String::format(char const* fmt, Arg_Ts&&...args)
31
+ template <typename... Parameter_Ts>
32
+ inline String String::format(char const* fmt, Parameter_Ts&&...args)
33
33
  {
34
- size_t size = std::snprintf(nullptr, 0, fmt, std::forward<Arg_Ts>(args)...);
34
+ size_t size = std::snprintf(nullptr, 0, fmt, std::forward<Parameter_Ts>(args)...);
35
35
  std::string temp(size, '\0');
36
36
 
37
37
  // size+1 avoids truncating the string. Otherwise snprintf writes n - 1 characters
38
38
  // to allow space for null character but we don't need that since std::string
39
39
  // will add a null character internally at n + 1
40
- std::snprintf(&temp[0], size + 1, fmt, std::forward<Arg_Ts>(args)...);
40
+ std::snprintf(&temp[0], size + 1, fmt, std::forward<Parameter_Ts>(args)...);
41
41
 
42
42
  String s = String(temp.c_str());
43
43
  return s;
@@ -97,7 +97,7 @@ namespace Rice::detail
97
97
  public:
98
98
  To_Ruby() = default;
99
99
 
100
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
100
+ explicit To_Ruby(Arg* arg) : arg_(arg)
101
101
  {
102
102
  }
103
103
 
@@ -107,7 +107,7 @@ namespace Rice::detail
107
107
  }
108
108
 
109
109
  private:
110
- Return* returnInfo_ = nullptr;
110
+ Arg* arg_ = nullptr;
111
111
  };
112
112
 
113
113
  template<>
@@ -116,11 +116,11 @@ namespace Rice::detail
116
116
  public:
117
117
  From_Ruby() = default;
118
118
 
119
- explicit From_Ruby(Arg* arg)
119
+ explicit From_Ruby(Arg* arg) : arg_(arg)
120
120
  {
121
121
  }
122
122
 
123
- Convertible is_convertible(VALUE value)
123
+ double is_convertible(VALUE value)
124
124
  {
125
125
  switch (rb_type(value))
126
126
  {
@@ -136,5 +136,8 @@ namespace Rice::detail
136
136
  {
137
137
  return String(value);
138
138
  }
139
+
140
+ private:
141
+ Arg* arg_ = nullptr;
139
142
  };
140
143
  }
@@ -67,7 +67,7 @@ namespace Rice::detail
67
67
  public:
68
68
  To_Ruby() = default;
69
69
 
70
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
70
+ explicit To_Ruby(Arg* arg) : arg_(arg)
71
71
  {
72
72
  }
73
73
 
@@ -77,7 +77,7 @@ namespace Rice::detail
77
77
  }
78
78
 
79
79
  private:
80
- Return* returnInfo_ = nullptr;
80
+ Arg* arg_ = nullptr;
81
81
  };
82
82
 
83
83
 
@@ -87,7 +87,7 @@ namespace Rice::detail
87
87
  public:
88
88
  To_Ruby() = default;
89
89
 
90
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
90
+ explicit To_Ruby(Arg* arg) : arg_(arg)
91
91
  {
92
92
  }
93
93
 
@@ -97,7 +97,7 @@ namespace Rice::detail
97
97
  }
98
98
 
99
99
  private:
100
- Return* returnInfo_ = nullptr;
100
+ Arg* arg_ = nullptr;
101
101
  };
102
102
 
103
103
  template<>
@@ -110,15 +110,15 @@ namespace Rice::detail
110
110
  {
111
111
  }
112
112
 
113
- Convertible is_convertible(VALUE value)
113
+ double is_convertible(VALUE value)
114
114
  {
115
115
  switch (rb_type(value))
116
116
  {
117
117
  case RUBY_T_SYMBOL:
118
118
  return Convertible::Exact;
119
119
  break;
120
- case RUBY_T_STRING:
121
- return Convertible::Cast;
120
+ case RUBY_T_STRING:
121
+ return Convertible::Exact;
122
122
  break;
123
123
  default:
124
124
  return Convertible::None;
@@ -33,8 +33,7 @@ inline auto& include_module(Module const& inc)
33
33
  template<typename Method_T, typename...Arg_Ts>
34
34
  inline auto& define_method(std::string name, Method_T&& method, const Arg_Ts&...args)
35
35
  {
36
- MethodInfo* methodInfo = new MethodInfo(detail::method_traits<Method_T>::arity, args...);
37
- this->wrap_native_method(this->value(), name, std::forward<Method_T>(method), methodInfo);
36
+ this->wrap_native_method(this->value(), name, std::forward<Method_T>(method), args...);
38
37
  return *this;
39
38
  }
40
39
 
@@ -52,8 +51,7 @@ inline auto& define_method(std::string name, Method_T&& method, const Arg_Ts&...
52
51
  template<typename Function_T, typename...Arg_Ts>
53
52
  inline auto& define_function(std::string name, Function_T&& func, const Arg_Ts&...args)
54
53
  {
55
- MethodInfo* methodInfo = new MethodInfo(detail::function_traits<Function_T>::arity, args...);
56
- this->wrap_native_function(this->value(), name, std::forward<Function_T>(func), methodInfo);
54
+ this->wrap_native_function(this->value(), name, std::forward<Function_T>(func), args...);
57
55
  return *this;
58
56
  }
59
57
 
@@ -75,8 +73,7 @@ inline auto& define_function(std::string name, Function_T&& func, const Arg_Ts&.
75
73
  template<typename Method_T, typename...Arg_Ts>
76
74
  inline auto& define_singleton_method(std::string name, Method_T&& method, const Arg_Ts&...args)
77
75
  {
78
- MethodInfo* methodInfo = new MethodInfo(detail::method_traits<Method_T>::arity, args...);
79
- this->wrap_native_method(rb_singleton_class(*this), name, std::forward<Method_T>(method), methodInfo);
76
+ this->wrap_native_method(rb_singleton_class(*this), name, std::forward<Method_T>(method), args...);
80
77
  return *this;
81
78
  }
82
79
 
@@ -94,8 +91,7 @@ inline auto& define_singleton_method(std::string name, Method_T&& method, const
94
91
  template<typename Function_T, typename...Arg_Ts>
95
92
  inline auto& define_singleton_function(std::string name, Function_T&& func, const Arg_Ts& ...args)
96
93
  {
97
- MethodInfo* methodInfo = new MethodInfo(detail::function_traits<Function_T>::arity, args...);
98
- this->wrap_native_function(rb_singleton_class(*this), name, std::forward<Function_T>(func), methodInfo);
94
+ this->wrap_native_function(rb_singleton_class(*this), name, std::forward<Function_T>(func), args...);
99
95
  return *this;
100
96
  }
101
97
 
@@ -112,7 +108,7 @@ inline auto& define_singleton_function(std::string name, Function_T&& func, cons
112
108
  * \return *this
113
109
  */
114
110
  template<typename Function_T, typename...Arg_Ts>
115
- inline auto& define_module_function(std::string name, Function_T&& func, const Arg_Ts& ...args)
111
+ inline auto& define_module_function(std::string name, Function_T&& func, Arg_Ts&& ...args)
116
112
  {
117
113
  if (this->rb_type() != T_MODULE)
118
114
  {
@@ -1,8 +1,6 @@
1
1
  #ifndef Rice__detail__InstanceRegistry__hpp_
2
2
  #define Rice__detail__InstanceRegistry__hpp_
3
3
 
4
- #include <map>
5
-
6
4
  namespace Rice::detail
7
5
  {
8
6
  class InstanceRegistry
@@ -11,8 +11,7 @@ namespace Rice::detail
11
11
  inline bool operator<(Resolved other);
12
12
  inline bool operator>(Resolved other);
13
13
 
14
- Convertible convertible;
15
- double parameterMatch;
14
+ double score; // Combined score: minParameterScore * parameterMatch
16
15
  Native* native;
17
16
  };
18
17
 
@@ -23,7 +22,8 @@ namespace Rice::detail
23
22
  Iterator,
24
23
  AttributeReader,
25
24
  AttributeWriter,
26
- Proc
25
+ Proc,
26
+ Callback
27
27
  };
28
28
 
29
29
  class Native
@@ -31,8 +31,9 @@ namespace Rice::detail
31
31
  public:
32
32
  static VALUE resolve(int argc, VALUE* argv, VALUE self);
33
33
  public:
34
- Native() = default;
35
- Native(std::vector<std::unique_ptr<ParameterAbstract>>&& parameters);
34
+ Native(std::string name);
35
+ Native(std::string name, std::unique_ptr<Return>&& returnInfo);
36
+ Native(std::string name, std::unique_ptr<Return>&& returnInfo, std::vector<std::unique_ptr<ParameterAbstract>>&& parameters);
36
37
  virtual ~Native() = default;
37
38
 
38
39
  Native(const Native&) = delete;
@@ -40,36 +41,45 @@ namespace Rice::detail
40
41
  void operator=(const Native&) = delete;
41
42
  void operator=(Native&&) = delete;
42
43
 
43
- virtual Resolved matches(size_t argc, const VALUE* argv, VALUE self);
44
- virtual VALUE operator()(size_t argc, const VALUE* argv, VALUE self) = 0;
44
+ virtual Resolved matches(std::map<std::string, VALUE>& values);
45
+ virtual VALUE operator()(std::map<std::string, VALUE>& values, VALUE self) = 0;
45
46
  virtual std::string toString() = 0;
46
47
 
47
48
  // Ruby API access
48
- virtual std::string name() = 0;
49
+ std::string name();
50
+ std::vector<const ParameterAbstract*> parameters();
49
51
  virtual NativeKind kind() = 0;
50
52
  virtual VALUE returnKlass() = 0;
51
- std::vector<const ParameterAbstract*> parameters();
52
53
 
53
54
  protected:
54
- template<typename T>
55
- static void verify_type(bool isBuffer);
55
+ template<typename T, bool isBuffer>
56
+ static void verify_type();
56
57
 
57
- template<typename Tuple_T, std::size_t ...Indices>
58
- static void verify_args(MethodInfo* methodInfo, std::index_sequence<Indices...> indices);
59
-
60
- std::vector<std::optional<VALUE>> getRubyValues(size_t argc, const VALUE* argv, bool validate);
58
+ static std::map<std::string, VALUE> readRubyArgs(size_t argc, const VALUE* argv);
59
+ std::vector<std::optional<VALUE>> getRubyValues(std::map<std::string, VALUE> values, bool validate);
61
60
  ParameterAbstract* getParameterByName(std::string name);
62
- Convertible matchParameters(std::vector<std::optional<VALUE>>& values);
61
+ double matchParameters(std::vector<std::optional<VALUE>>& values, size_t argc);
62
+
63
+ template<typename Parameter_Tuple, typename... Arg_Ts>
64
+ static std::vector<std::unique_ptr<ParameterAbstract>> create_parameters(Arg_Ts&& ...args);
63
65
 
64
- template<typename Tuple_T>
65
- static std::vector<std::unique_ptr<ParameterAbstract>> create_parameters(MethodInfo* methodInfo);
66
+ template<typename... Arg_Ts>
67
+ static std::unique_ptr<Return> create_return(Arg_Ts& ...args);
66
68
 
67
- template<typename Tuple_T, std::size_t ...Indices>
68
- static inline void create_parameters_impl(std::vector<std::unique_ptr<ParameterAbstract>>& parameters, MethodInfo* methodInfo, std::index_sequence<Indices...> indices);
69
+ // Do we need to keep alive any arguments?
70
+ void checkKeepAlive(VALUE self, VALUE returnValue, std::vector<std::optional<VALUE>>& rubyValues);
71
+
72
+ private:
73
+ template<typename Parameter_Tuple, typename Arg_Tuple, std::size_t ...Indices>
74
+ static inline void create_parameters_impl(std::vector<std::unique_ptr<ParameterAbstract>>& parameters, std::index_sequence<Indices...> indices, std::vector<std::unique_ptr<Arg>>&& args);
75
+
76
+ template<typename Parameter_Tuple, typename Arg_Tuple, size_t I>
77
+ static void verify_parameter();
69
78
 
70
79
  protected:
80
+ std::string name_;
81
+ std::unique_ptr<Return> returnInfo_;
71
82
  std::vector<std::unique_ptr<ParameterAbstract>> parameters_;
72
-
73
83
  };
74
84
  }
75
85