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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -1
- data/CMakeLists.txt +14 -22
- data/CMakePresets.json +203 -75
- data/FindRuby.cmake +358 -123
- data/bin/rice-doc.rb +56 -141
- data/include/rice/api.hpp +248 -0
- data/include/rice/rice.hpp +2237 -1657
- data/include/rice/stl.hpp +346 -443
- data/lib/rice/doc/config.rb +70 -0
- data/lib/rice/doc/cpp_reference.rb +1 -4
- data/lib/rice/doc/mkdocs.rb +58 -20
- data/lib/rice/doc/rice.rb +20 -0
- data/lib/rice/doc.rb +1 -0
- data/lib/rice/make_rice_headers.rb +7 -0
- data/lib/rice/native_registry.rb +2 -2
- data/lib/rice/rbs.rb +2 -2
- data/lib/rice/version.rb +1 -1
- data/lib/rubygems_plugin.rb +12 -9
- data/rice/Arg.hpp +12 -6
- data/rice/Arg.ipp +14 -7
- data/rice/Buffer.ipp +44 -40
- data/rice/Callback.hpp +1 -1
- data/rice/Callback.ipp +2 -7
- data/rice/Constructor.hpp +1 -1
- data/rice/Constructor.ipp +11 -11
- data/rice/Data_Object.ipp +15 -15
- data/rice/Data_Type.hpp +9 -10
- data/rice/Data_Type.ipp +22 -25
- data/rice/Director.hpp +1 -0
- data/rice/Enum.ipp +58 -39
- data/rice/Exception.hpp +4 -4
- data/rice/Exception.ipp +7 -7
- data/rice/NoGVL.hpp +13 -0
- data/rice/Reference.hpp +56 -0
- data/rice/Reference.ipp +96 -0
- data/rice/Return.hpp +4 -1
- data/rice/Return.ipp +0 -6
- data/rice/cpp_api/Array.hpp +41 -4
- data/rice/cpp_api/Array.ipp +105 -9
- data/rice/cpp_api/Class.hpp +2 -2
- data/rice/cpp_api/Class.ipp +4 -4
- data/rice/cpp_api/Hash.ipp +7 -4
- data/rice/cpp_api/Module.hpp +4 -4
- data/rice/cpp_api/Module.ipp +12 -10
- data/rice/cpp_api/Object.hpp +4 -4
- data/rice/cpp_api/Object.ipp +15 -12
- data/rice/cpp_api/String.hpp +2 -2
- data/rice/cpp_api/String.ipp +11 -8
- data/rice/cpp_api/Symbol.ipp +7 -7
- data/rice/cpp_api/shared_methods.hpp +5 -9
- data/rice/detail/InstanceRegistry.hpp +0 -2
- data/rice/detail/Native.hpp +31 -21
- data/rice/detail/Native.ipp +282 -130
- data/rice/detail/NativeAttributeGet.hpp +5 -7
- data/rice/detail/NativeAttributeGet.ipp +26 -26
- data/rice/detail/NativeAttributeSet.hpp +2 -4
- data/rice/detail/NativeAttributeSet.ipp +20 -16
- data/rice/detail/NativeCallback.hpp +77 -0
- data/rice/detail/NativeCallback.ipp +280 -0
- data/rice/detail/NativeFunction.hpp +11 -21
- data/rice/detail/NativeFunction.ipp +58 -119
- data/rice/detail/NativeInvoker.hpp +4 -4
- data/rice/detail/NativeInvoker.ipp +7 -7
- data/rice/detail/NativeIterator.hpp +2 -4
- data/rice/detail/NativeIterator.ipp +18 -14
- data/rice/detail/NativeMethod.hpp +10 -20
- data/rice/detail/NativeMethod.ipp +54 -114
- data/rice/detail/NativeProc.hpp +5 -7
- data/rice/detail/NativeProc.ipp +39 -28
- data/rice/detail/NativeRegistry.hpp +0 -1
- data/rice/detail/Parameter.hpp +15 -8
- data/rice/detail/Parameter.ipp +102 -43
- data/rice/detail/Proc.ipp +14 -28
- data/rice/detail/RubyType.ipp +2 -53
- data/rice/detail/Type.hpp +23 -7
- data/rice/detail/Type.ipp +73 -93
- data/rice/detail/TypeRegistry.ipp +5 -4
- data/rice/detail/Wrapper.hpp +1 -1
- data/rice/detail/Wrapper.ipp +18 -10
- data/rice/detail/from_ruby.hpp +8 -6
- data/rice/detail/from_ruby.ipp +306 -173
- data/rice/detail/ruby.hpp +23 -0
- data/rice/libc/file.hpp +4 -4
- data/rice/rice.hpp +6 -8
- data/rice/rice_api/Native.ipp +5 -1
- data/rice/rice_api/Parameter.ipp +1 -1
- data/rice/ruby_mark.hpp +2 -1
- data/rice/stl/complex.ipp +12 -8
- data/rice/stl/map.ipp +27 -22
- data/rice/stl/monostate.ipp +16 -12
- data/rice/stl/multimap.hpp +0 -2
- data/rice/stl/multimap.ipp +27 -22
- data/rice/stl/optional.ipp +27 -11
- data/rice/stl/pair.ipp +5 -5
- data/rice/stl/reference_wrapper.ipp +5 -4
- data/rice/stl/set.ipp +16 -16
- data/rice/stl/shared_ptr.hpp +0 -16
- data/rice/stl/shared_ptr.ipp +34 -190
- data/rice/stl/string.ipp +18 -18
- data/rice/stl/string_view.ipp +1 -1
- data/rice/stl/tuple.ipp +15 -36
- data/rice/stl/unique_ptr.ipp +18 -8
- data/rice/stl/unordered_map.ipp +20 -15
- data/rice/stl/variant.ipp +37 -21
- data/rice/stl/vector.ipp +41 -36
- data/rice/traits/function_traits.hpp +19 -19
- data/rice/traits/method_traits.hpp +4 -4
- data/rice/traits/rice_traits.hpp +162 -39
- data/rice.gemspec +1 -3
- data/test/test_Array.cpp +261 -3
- data/test/test_Attribute.cpp +6 -3
- data/test/test_Buffer.cpp +6 -42
- data/test/test_Callback.cpp +77 -23
- data/test/test_Data_Object.cpp +1 -1
- data/test/test_Data_Type.cpp +21 -22
- data/test/test_Director.cpp +2 -4
- data/test/test_Enum.cpp +34 -5
- data/test/test_File.cpp +9 -5
- data/test/test_From_Ruby.cpp +4 -3
- data/test/test_GVL.cpp +3 -3
- data/test/test_Hash.cpp +1 -1
- data/test/test_Iterator.cpp +54 -22
- data/test/test_Keep_Alive.cpp +1 -1
- data/test/test_Keep_Alive_No_Wrapper.cpp +1 -1
- data/test/test_Module.cpp +5 -5
- data/test/test_Overloads.cpp +345 -48
- data/test/test_Proc.cpp +54 -0
- data/test/test_Reference.cpp +181 -0
- data/test/test_Self.cpp +2 -2
- data/test/test_Stl_Set.cpp +6 -6
- data/test/test_Stl_SharedPtr.cpp +54 -30
- data/test/test_Stl_String_View.cpp +4 -2
- data/test/test_Stl_Tuple.cpp +1 -1
- data/test/test_Stl_Variant.cpp +6 -14
- data/test/test_Stl_Vector.cpp +61 -30
- data/test/test_String.cpp +4 -2
- data/test/test_Struct.cpp +1 -1
- data/test/test_Symbol.cpp +1 -1
- data/test/test_To_Ruby.cpp +1 -0
- data/test/test_Type.cpp +36 -35
- data/test/test_global_functions.cpp +1 -1
- data/test/unittest.cpp +1 -1
- data/test/unittest.hpp +5 -5
- metadata +10 -10
- data/rice/Function.hpp +0 -17
- data/rice/Function.ipp +0 -13
- data/rice/detail/MethodInfo.hpp +0 -48
- data/rice/detail/MethodInfo.ipp +0 -99
- data/rice/detail/NativeCallbackFFI.hpp +0 -55
- data/rice/detail/NativeCallbackFFI.ipp +0 -152
- data/rice/detail/NativeCallbackSimple.hpp +0 -30
- data/rice/detail/NativeCallbackSimple.ipp +0 -29
data/rice/cpp_api/Hash.ipp
CHANGED
|
@@ -234,7 +234,7 @@ namespace Rice::detail
|
|
|
234
234
|
public:
|
|
235
235
|
To_Ruby() = default;
|
|
236
236
|
|
|
237
|
-
explicit To_Ruby(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
data/rice/cpp_api/Module.hpp
CHANGED
|
@@ -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,
|
|
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,
|
|
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.
|
data/rice/cpp_api/Module.ipp
CHANGED
|
@@ -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,
|
|
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::
|
|
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,
|
|
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::
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
129
|
+
Arg* arg_ = nullptr;
|
|
128
130
|
};
|
|
129
131
|
|
|
130
132
|
template<>
|
data/rice/cpp_api/Object.hpp
CHANGED
|
@@ -181,8 +181,8 @@ namespace Rice
|
|
|
181
181
|
* float ret = x.call<float>("foo", z, 42);
|
|
182
182
|
* \endcode
|
|
183
183
|
*/
|
|
184
|
-
template<typename ...
|
|
185
|
-
Object call(Identifier id,
|
|
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 ...
|
|
208
|
-
Object call_kw(Identifier id,
|
|
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
|
data/rice/cpp_api/Object.ipp
CHANGED
|
@@ -27,8 +27,8 @@ namespace Rice
|
|
|
27
27
|
return *this;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
template<typename ...
|
|
31
|
-
inline Object Object::call(Identifier id,
|
|
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...(
|
|
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 ...
|
|
45
|
-
inline Object Object::call_kw(Identifier id,
|
|
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...(
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
data/rice/cpp_api/String.hpp
CHANGED
|
@@ -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...
|
|
42
|
-
static inline String format(char const* fmt,
|
|
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.
|
data/rice/cpp_api/String.ipp
CHANGED
|
@@ -28,16 +28,16 @@ namespace Rice
|
|
|
28
28
|
{
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
template <typename...
|
|
32
|
-
inline String String::format(char const* fmt,
|
|
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<
|
|
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<
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
data/rice/cpp_api/Symbol.ipp
CHANGED
|
@@ -67,7 +67,7 @@ namespace Rice::detail
|
|
|
67
67
|
public:
|
|
68
68
|
To_Ruby() = default;
|
|
69
69
|
|
|
70
|
-
explicit To_Ruby(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
121
|
-
return Convertible::
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
{
|
data/rice/detail/Native.hpp
CHANGED
|
@@ -11,8 +11,7 @@ namespace Rice::detail
|
|
|
11
11
|
inline bool operator<(Resolved other);
|
|
12
12
|
inline bool operator>(Resolved other);
|
|
13
13
|
|
|
14
|
-
|
|
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()
|
|
35
|
-
Native(std::
|
|
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(
|
|
44
|
-
virtual VALUE operator()(
|
|
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
|
-
|
|
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(
|
|
55
|
+
template<typename T, bool isBuffer>
|
|
56
|
+
static void verify_type();
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
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
|
|
65
|
-
static std::
|
|
66
|
+
template<typename... Arg_Ts>
|
|
67
|
+
static std::unique_ptr<Return> create_return(Arg_Ts& ...args);
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|