rice 4.6.1 → 4.7.1
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 +38 -0
- data/CMakeLists.txt +0 -4
- data/Rakefile +2 -8
- data/bin/rice-doc.rb +211 -0
- data/bin/rice-rbs.rb +92 -0
- data/include/rice/rice.hpp +4694 -3704
- data/include/rice/stl.hpp +840 -294
- data/lib/rice/doc/cpp_reference.rb +166 -0
- data/lib/rice/doc/doxygen.rb +294 -0
- data/lib/rice/doc/mkdocs.rb +298 -0
- data/lib/rice/doc/rice.rb +29 -0
- data/lib/rice/doc/ruby.rb +37 -0
- data/lib/rice/doc.rb +5 -0
- data/lib/{make_rice_headers.rb → rice/make_rice_headers.rb} +3 -0
- data/lib/rice/native.rb +18 -0
- data/lib/rice/native_registry.rb +21 -0
- data/lib/rice/parameter.rb +7 -0
- data/lib/rice/rbs.rb +104 -0
- data/lib/rice/version.rb +1 -1
- data/lib/rice.rb +4 -0
- data/lib/rubygems/cmake_builder.rb +24 -27
- data/rice/Arg.hpp +4 -4
- data/rice/Arg.ipp +4 -4
- data/rice/Buffer.hpp +32 -28
- data/rice/Buffer.ipp +306 -178
- data/rice/Data_Object.ipp +136 -88
- data/rice/Data_Type.hpp +5 -7
- data/rice/Data_Type.ipp +48 -29
- data/rice/Enum.ipp +15 -21
- data/rice/Function.hpp +17 -0
- data/rice/Function.ipp +13 -0
- data/rice/Pointer.hpp +15 -0
- data/rice/Pointer.ipp +49 -0
- data/rice/Return.hpp +1 -1
- data/rice/Return.ipp +2 -2
- data/rice/api.hpp +30 -0
- data/rice/cpp_api/Array.hpp +4 -4
- data/rice/cpp_api/Array.ipp +50 -5
- data/rice/cpp_api/Class.hpp +0 -5
- data/rice/cpp_api/Class.ipp +19 -0
- data/rice/cpp_api/Hash.ipp +20 -0
- data/rice/cpp_api/Module.hpp +6 -3
- data/rice/cpp_api/Module.ipp +49 -11
- data/rice/cpp_api/Object.ipp +31 -2
- data/rice/cpp_api/String.hpp +1 -2
- data/rice/cpp_api/String.ipp +21 -1
- data/rice/cpp_api/Struct.ipp +5 -0
- data/rice/cpp_api/Symbol.ipp +43 -0
- data/rice/cpp_api/shared_methods.hpp +12 -12
- data/rice/detail/MethodInfo.hpp +4 -2
- data/rice/detail/MethodInfo.ipp +19 -3
- data/rice/detail/ModuleRegistry.hpp +18 -0
- data/rice/detail/ModuleRegistry.ipp +25 -0
- data/rice/detail/Native.hpp +45 -2
- data/rice/detail/Native.ipp +196 -6
- data/rice/detail/NativeAttributeGet.hpp +9 -4
- data/rice/detail/NativeAttributeGet.ipp +65 -11
- data/rice/detail/NativeAttributeSet.hpp +4 -0
- data/rice/detail/NativeAttributeSet.ipp +30 -2
- data/rice/detail/NativeCallbackFFI.ipp +2 -2
- data/rice/detail/NativeCallbackSimple.ipp +1 -1
- data/rice/detail/NativeFunction.hpp +11 -49
- data/rice/detail/NativeFunction.ipp +82 -379
- data/rice/detail/NativeInvoker.hpp +74 -0
- data/rice/detail/NativeInvoker.ipp +197 -0
- data/rice/detail/NativeIterator.hpp +4 -0
- data/rice/detail/NativeIterator.ipp +19 -0
- data/rice/detail/NativeMethod.hpp +97 -0
- data/rice/detail/NativeMethod.ipp +332 -0
- data/rice/detail/NativeProc.hpp +51 -0
- data/rice/detail/NativeProc.ipp +133 -0
- data/rice/detail/NativeRegistry.hpp +8 -0
- data/rice/detail/NativeRegistry.ipp +26 -0
- data/rice/detail/Parameter.hpp +47 -0
- data/rice/detail/Parameter.ipp +105 -0
- data/rice/detail/Proc.ipp +14 -13
- data/rice/detail/Registries.hpp +1 -0
- data/rice/detail/RubyType.hpp +0 -2
- data/rice/detail/RubyType.ipp +15 -33
- data/rice/detail/Type.hpp +44 -8
- data/rice/detail/Type.ipp +151 -49
- data/rice/detail/TypeRegistry.hpp +3 -0
- data/rice/detail/TypeRegistry.ipp +17 -27
- data/rice/detail/Types.ipp +430 -0
- data/rice/detail/Wrapper.hpp +12 -0
- data/rice/detail/Wrapper.ipp +45 -2
- data/rice/detail/from_ruby.ipp +567 -1073
- data/rice/detail/ruby.hpp +1 -0
- data/rice/detail/to_ruby.ipp +4 -635
- data/rice/libc/file.ipp +3 -6
- data/rice/rice.hpp +22 -12
- data/rice/rice_api/Arg.hpp +7 -0
- data/rice/rice_api/Arg.ipp +9 -0
- data/rice/rice_api/ModuleRegistry.hpp +7 -0
- data/rice/rice_api/ModuleRegistry.ipp +10 -0
- data/rice/rice_api/Native.hpp +7 -0
- data/rice/rice_api/Native.ipp +52 -0
- data/rice/rice_api/NativeRegistry.hpp +7 -0
- data/rice/rice_api/NativeRegistry.ipp +21 -0
- data/rice/rice_api/Parameter.hpp +7 -0
- data/rice/rice_api/Parameter.ipp +11 -0
- data/rice/rice_api/Registries.hpp +6 -0
- data/rice/rice_api/Registries.ipp +12 -0
- data/rice/rice_api/TypeRegistry.hpp +7 -0
- data/rice/rice_api/TypeRegistry.ipp +10 -0
- data/rice/stl/complex.ipp +35 -0
- data/rice/stl/exception.ipp +20 -7
- data/rice/stl/filesystem.hpp +6 -0
- data/rice/stl/filesystem.ipp +34 -0
- data/rice/stl/map.ipp +13 -21
- data/rice/stl/monostate.ipp +37 -1
- data/rice/stl/multimap.ipp +17 -24
- data/rice/stl/optional.ipp +47 -2
- data/rice/stl/pair.ipp +23 -58
- data/rice/stl/reference_wrapper.ipp +22 -1
- data/rice/stl/set.ipp +17 -9
- data/rice/stl/shared_ptr.ipp +44 -17
- data/rice/stl/string.ipp +175 -7
- data/rice/stl/string_view.ipp +23 -0
- data/rice/stl/tuple.ipp +38 -9
- data/rice/stl/unique_ptr.ipp +46 -2
- data/rice/stl/unordered_map.ipp +13 -21
- data/rice/stl/variant.ipp +47 -11
- data/rice/stl/vector.ipp +183 -104
- data/rice/stl.hpp +1 -0
- data/rice/traits/function_traits.hpp +2 -2
- data/rice/traits/method_traits.hpp +5 -16
- data/rice/traits/rice_traits.hpp +24 -4
- data/rice.gemspec +10 -22
- data/test/embed_ruby.cpp +0 -3
- data/test/test_Array.cpp +38 -38
- data/test/test_Attribute.cpp +187 -2
- data/test/test_Buffer.cpp +302 -26
- data/test/test_Callback.cpp +2 -3
- data/test/test_Class.cpp +5 -5
- data/test/test_Data_Object.cpp +1 -56
- data/test/test_Data_Type.cpp +20 -30
- data/test/test_Enum.cpp +4 -46
- data/test/test_From_Ruby.cpp +89 -82
- data/test/test_GVL.cpp +109 -0
- data/test/test_Iterator.cpp +1 -1
- data/test/test_Keep_Alive_No_Wrapper.cpp +5 -3
- data/test/test_Module.cpp +8 -9
- data/test/test_Object.cpp +1 -1
- data/test/test_Overloads.cpp +58 -10
- data/test/test_Stl_Map.cpp +8 -8
- data/test/test_Stl_Multimap.cpp +4 -4
- data/test/test_Stl_Pair.cpp +5 -3
- data/test/test_Stl_SharedPtr.cpp +24 -12
- data/test/test_Stl_String_View.cpp +10 -0
- data/test/test_Stl_Tuple.cpp +1 -1
- data/test/test_Stl_UniquePtr.cpp +8 -0
- data/test/test_Stl_Unordered_Map.cpp +9 -9
- data/test/test_Stl_Variant.cpp +9 -3
- data/test/test_Stl_Vector.cpp +118 -13
- data/test/test_Symbol.cpp +12 -0
- data/test/test_To_Ruby.cpp +35 -28
- data/test/test_Type.cpp +256 -53
- data/test/unittest.hpp +35 -0
- metadata +52 -34
- data/rice/Init.hpp +0 -8
- data/rice/Init.ipp +0 -8
- data/rice/detail/RubyFunction.hpp +0 -31
- data/rice/detail/RubyFunction.ipp +0 -77
- data/sample/callbacks/extconf.rb +0 -5
- data/sample/callbacks/sample_callbacks.cpp +0 -35
- data/sample/callbacks/test.rb +0 -28
- data/sample/enum/extconf.rb +0 -5
- data/sample/enum/sample_enum.cpp +0 -40
- data/sample/enum/test.rb +0 -8
- data/sample/inheritance/animals.cpp +0 -82
- data/sample/inheritance/extconf.rb +0 -5
- data/sample/inheritance/test.rb +0 -7
- data/sample/map/extconf.rb +0 -5
- data/sample/map/map.cpp +0 -73
- data/sample/map/test.rb +0 -7
- data/test/ext/t1/Foo.hpp +0 -10
- data/test/ext/t1/extconf.rb +0 -4
- data/test/ext/t1/t1.cpp +0 -13
- data/test/ext/t2/extconf.rb +0 -4
- data/test/ext/t2/t2.cpp +0 -11
- data/test/ruby/test_callbacks_sample.rb +0 -28
- data/test/ruby/test_multiple_extensions.rb +0 -18
- data/test/ruby/test_multiple_extensions_same_class.rb +0 -14
- data/test/ruby/test_multiple_extensions_with_inheritance.rb +0 -20
- /data/test/{test_Stl_Type.cpp → test_Stl_Type_Info.cpp} +0 -0
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
#include <any>
|
|
3
|
-
#include <tuple>
|
|
4
|
-
|
|
5
|
-
namespace Rice::detail
|
|
6
|
-
{
|
|
7
|
-
template<typename Function_T, typename...Arg_Ts>
|
|
8
|
-
inline RubyFunction<Function_T, Arg_Ts...>::RubyFunction(Function_T func, const Arg_Ts&... args)
|
|
9
|
-
: func_(func), args_(std::forward_as_tuple(args...))
|
|
10
|
-
{
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
template<typename Function_T, typename...Arg_Ts>
|
|
14
|
-
inline typename RubyFunction<Function_T, Arg_Ts...>::Return_T RubyFunction<Function_T, Arg_Ts...>::operator()()
|
|
15
|
-
{
|
|
16
|
-
// Setup a thread local variable to capture the result of the Ruby function call.
|
|
17
|
-
// We use thread_local because the lambda has to be captureless so it can
|
|
18
|
-
// be converted to a function pointer callable by C.
|
|
19
|
-
// The thread local variable avoids having to cast the result to VALUE and then
|
|
20
|
-
// back again to Return_T. The problem with that is the translation is not lossless
|
|
21
|
-
// in some cases - for example a double with value of -1.0 does not roundrip.
|
|
22
|
-
//
|
|
23
|
-
thread_local std::any result;
|
|
24
|
-
|
|
25
|
-
// Callback that will invoke the Ruby function
|
|
26
|
-
using Functor_T = RubyFunction<Function_T, Arg_Ts...>;
|
|
27
|
-
auto callback = [](VALUE value) -> VALUE
|
|
28
|
-
{
|
|
29
|
-
Functor_T* functor = (Functor_T*)value;
|
|
30
|
-
|
|
31
|
-
if constexpr (std::is_same_v<Return_T, void>)
|
|
32
|
-
{
|
|
33
|
-
std::apply(functor->func_, functor->args_);
|
|
34
|
-
}
|
|
35
|
-
else
|
|
36
|
-
{
|
|
37
|
-
result = std::apply(functor->func_, functor->args_);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return Qnil;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// Now call rb_protect which will invoke the callback lambda above
|
|
44
|
-
int state = (int)JumpException::RUBY_TAG_NONE;
|
|
45
|
-
rb_protect(callback, (VALUE)this, &state);
|
|
46
|
-
|
|
47
|
-
// Did anything go wrong?
|
|
48
|
-
if (state == JumpException::RUBY_TAG_NONE)
|
|
49
|
-
{
|
|
50
|
-
if constexpr (!std::is_same_v<Return_T, void>)
|
|
51
|
-
{
|
|
52
|
-
return std::any_cast<Return_T>(result);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else
|
|
56
|
-
{
|
|
57
|
-
VALUE err = rb_errinfo();
|
|
58
|
-
if (state == JumpException::RUBY_TAG_RAISE && RB_TEST(err))
|
|
59
|
-
{
|
|
60
|
-
rb_set_errinfo(Qnil);
|
|
61
|
-
throw Rice::Exception(err);
|
|
62
|
-
}
|
|
63
|
-
else
|
|
64
|
-
{
|
|
65
|
-
throw Rice::JumpException((Rice::JumpException::ruby_tag_type)state);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Create a functor for calling a Ruby function and define some aliases for readability.
|
|
71
|
-
template<typename Function_T, typename ...Arg_Ts>
|
|
72
|
-
auto protect(Function_T func, Arg_Ts...args)
|
|
73
|
-
{
|
|
74
|
-
auto rubyFunction = RubyFunction<Function_T, Arg_Ts...>(func, std::forward<Arg_Ts>(args)...);
|
|
75
|
-
return rubyFunction();
|
|
76
|
-
}
|
|
77
|
-
}
|
data/sample/callbacks/extconf.rb
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#include <rice/rice.hpp>
|
|
2
|
-
|
|
3
|
-
using namespace Rice;
|
|
4
|
-
|
|
5
|
-
namespace
|
|
6
|
-
{
|
|
7
|
-
|
|
8
|
-
class CallbackHolder
|
|
9
|
-
{
|
|
10
|
-
public:
|
|
11
|
-
|
|
12
|
-
void registerCallback(Rice::Object cb)
|
|
13
|
-
{
|
|
14
|
-
callback_ = cb;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
Rice::Object fireCallback(Rice::String param)
|
|
18
|
-
{
|
|
19
|
-
return callback_.call("call", param);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
Rice::Object callback_;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
} // namespace
|
|
26
|
-
|
|
27
|
-
extern "C"
|
|
28
|
-
void Init_sample_callbacks()
|
|
29
|
-
{
|
|
30
|
-
define_class<CallbackHolder>("CallbackHolder")
|
|
31
|
-
.define_constructor(Constructor<CallbackHolder>())
|
|
32
|
-
.define_method("register_callback", &CallbackHolder::registerCallback)
|
|
33
|
-
.define_method("fire_callback", &CallbackHolder::fireCallback);
|
|
34
|
-
}
|
|
35
|
-
|
data/sample/callbacks/test.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require 'sample_callbacks'
|
|
2
|
-
|
|
3
|
-
def hello(message)
|
|
4
|
-
"Hello #{message}"
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
cb1 = CallbackHolder.new
|
|
8
|
-
cb2 = CallbackHolder.new
|
|
9
|
-
cb3 = CallbackHolder.new
|
|
10
|
-
|
|
11
|
-
cb1.register_callback(lambda do |param|
|
|
12
|
-
"Callback 1 got param #{param}"
|
|
13
|
-
end)
|
|
14
|
-
|
|
15
|
-
cb2.register_callback(lambda do |param|
|
|
16
|
-
"Callback 2 got param #{param}"
|
|
17
|
-
end)
|
|
18
|
-
|
|
19
|
-
cb3.register_callback method(:hello)
|
|
20
|
-
|
|
21
|
-
puts "Calling Callback 1"
|
|
22
|
-
puts cb1.fire_callback("Hello")
|
|
23
|
-
|
|
24
|
-
puts "Calling Callback 2"
|
|
25
|
-
puts cb2.fire_callback("World")
|
|
26
|
-
|
|
27
|
-
puts "Calling Callback 3"
|
|
28
|
-
puts cb3.fire_callback("Ruby")
|
data/sample/enum/extconf.rb
DELETED
data/sample/enum/sample_enum.cpp
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
#include <rice/rice.hpp>
|
|
2
|
-
|
|
3
|
-
using namespace Rice;
|
|
4
|
-
|
|
5
|
-
namespace
|
|
6
|
-
{
|
|
7
|
-
|
|
8
|
-
enum Sample_Enum
|
|
9
|
-
{
|
|
10
|
-
SE_FOO = 1,
|
|
11
|
-
SE_BAR = 42,
|
|
12
|
-
SE_BAZ = 100,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
char const * description(Sample_Enum e)
|
|
16
|
-
{
|
|
17
|
-
switch(e)
|
|
18
|
-
{
|
|
19
|
-
case SE_FOO: return "Fairly Ordinary Object";
|
|
20
|
-
case SE_BAR: return "Beginner's All-purpose Ratchet";
|
|
21
|
-
case SE_BAZ: return "Better than A Zebra";
|
|
22
|
-
}
|
|
23
|
-
return "???";
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
} // namespace
|
|
27
|
-
|
|
28
|
-
extern "C"
|
|
29
|
-
void Init_sample_enum()
|
|
30
|
-
{
|
|
31
|
-
Rice::Enum<Sample_Enum> sample_enum_type =
|
|
32
|
-
define_enum<Sample_Enum>("Sample_Enum")
|
|
33
|
-
.define_value("FOO", SE_FOO)
|
|
34
|
-
.define_value("BAR", SE_BAR)
|
|
35
|
-
.define_value("BAZ", SE_BAZ);
|
|
36
|
-
|
|
37
|
-
sample_enum_type
|
|
38
|
-
.define_method("description", description);
|
|
39
|
-
}
|
|
40
|
-
|
data/sample/enum/test.rb
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
#include <rice/rice.hpp>
|
|
2
|
-
|
|
3
|
-
using namespace Rice;
|
|
4
|
-
|
|
5
|
-
class Organism
|
|
6
|
-
{
|
|
7
|
-
public:
|
|
8
|
-
virtual ~Organism() = default;
|
|
9
|
-
virtual char const * name() = 0;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
class Animal
|
|
13
|
-
: public Organism
|
|
14
|
-
{
|
|
15
|
-
public:
|
|
16
|
-
virtual char const * speak() = 0;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
class Bear
|
|
20
|
-
: public Animal
|
|
21
|
-
{
|
|
22
|
-
public:
|
|
23
|
-
char const * name() override
|
|
24
|
-
{
|
|
25
|
-
return "Bear";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
char const * speak() override
|
|
29
|
-
{
|
|
30
|
-
return "I'm smarter than the average bear";
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
class Dog
|
|
35
|
-
: public Animal
|
|
36
|
-
{
|
|
37
|
-
public:
|
|
38
|
-
char const * name() override
|
|
39
|
-
{
|
|
40
|
-
return "Dog";
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
char const * speak() override
|
|
44
|
-
{
|
|
45
|
-
return "Woof woof";
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
class Rabbit
|
|
50
|
-
: public Animal
|
|
51
|
-
{
|
|
52
|
-
public:
|
|
53
|
-
char const * name() override
|
|
54
|
-
{
|
|
55
|
-
return "Rabbit";
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
char const * speak() override
|
|
59
|
-
{
|
|
60
|
-
return "What's up, doc?";
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
extern "C"
|
|
65
|
-
void Init_animals(void)
|
|
66
|
-
{
|
|
67
|
-
define_class<Organism>("Organism")
|
|
68
|
-
.define_method("name", &Organism::name);
|
|
69
|
-
|
|
70
|
-
define_class<Animal, Organism>("Animal")
|
|
71
|
-
.define_method("speak", &Animal::speak);
|
|
72
|
-
|
|
73
|
-
define_class<Bear, Animal>("Bear")
|
|
74
|
-
.define_constructor(Constructor<Bear>());
|
|
75
|
-
|
|
76
|
-
define_class<Dog, Animal>("Dog")
|
|
77
|
-
.define_constructor(Constructor<Dog>());
|
|
78
|
-
|
|
79
|
-
define_class<Rabbit, Animal>("Rabbit")
|
|
80
|
-
.define_constructor(Constructor<Rabbit>());
|
|
81
|
-
}
|
|
82
|
-
|
data/sample/inheritance/test.rb
DELETED
data/sample/map/extconf.rb
DELETED
data/sample/map/map.cpp
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
#include <rice/rice.hpp>
|
|
2
|
-
|
|
3
|
-
#include <map>
|
|
4
|
-
|
|
5
|
-
using namespace Rice;
|
|
6
|
-
|
|
7
|
-
namespace
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
class Map
|
|
11
|
-
{
|
|
12
|
-
private:
|
|
13
|
-
struct Ruby_Value_Compare
|
|
14
|
-
{
|
|
15
|
-
bool operator()(Object lhs, Object rhs) const
|
|
16
|
-
{
|
|
17
|
-
Object result = lhs.call("<", rhs);
|
|
18
|
-
return result.test();
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
typedef std::map<Object, Object, Ruby_Value_Compare> Value_Map;
|
|
23
|
-
|
|
24
|
-
public:
|
|
25
|
-
Object bracket(Object k)
|
|
26
|
-
{
|
|
27
|
-
Value_Map::iterator it = map_.find(k);
|
|
28
|
-
return it == map_.end() ? Object(Qnil) : it->second;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
Object bracket_equals(Object k, Object v)
|
|
32
|
-
{
|
|
33
|
-
map_[k] = v;
|
|
34
|
-
return Qnil;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
Value_Map::iterator begin() { return map_.begin(); }
|
|
38
|
-
Value_Map::iterator end() { return map_.end(); }
|
|
39
|
-
|
|
40
|
-
typedef Value_Map::value_type value_type;
|
|
41
|
-
typedef Value_Map::iterator iterator;
|
|
42
|
-
|
|
43
|
-
private:
|
|
44
|
-
Value_Map map_;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
} // namespace
|
|
48
|
-
|
|
49
|
-
template<>
|
|
50
|
-
struct detail::To_Ruby<Map::value_type>
|
|
51
|
-
{
|
|
52
|
-
static VALUE convert(Map::value_type const & pair)
|
|
53
|
-
{
|
|
54
|
-
return detail::protect(rb_assoc_new, pair.first.value(), pair.second.value());
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
#include <iostream>
|
|
59
|
-
extern "C"
|
|
60
|
-
void Init_map(void)
|
|
61
|
-
{
|
|
62
|
-
Rice::Module rb_mStd = define_module("Std");
|
|
63
|
-
|
|
64
|
-
// TODO: no delete method on the map, because I'm not sure how to
|
|
65
|
-
// make delete work properly while iterating
|
|
66
|
-
Data_Type<Map> rb_cMap =
|
|
67
|
-
define_class_under<Map>(rb_mStd, "Map")
|
|
68
|
-
.define_constructor(Constructor<Map>())
|
|
69
|
-
.define_method("[]", &Map::bracket)
|
|
70
|
-
.define_method("[]=", &Map::bracket_equals)
|
|
71
|
-
.define_iterator(&Map::begin, &Map::end)
|
|
72
|
-
.include_module(rb_mEnumerable);
|
|
73
|
-
}
|
data/sample/map/test.rb
DELETED
data/test/ext/t1/Foo.hpp
DELETED
data/test/ext/t1/extconf.rb
DELETED
data/test/ext/t1/t1.cpp
DELETED
data/test/ext/t2/extconf.rb
DELETED
data/test/ext/t2/t2.cpp
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
$: << File.join(File.dirname(__FILE__), '..', 'sample')
|
|
2
|
-
|
|
3
|
-
require 'rubygems'
|
|
4
|
-
gem 'minitest'
|
|
5
|
-
require 'minitest/autorun'
|
|
6
|
-
require_relative '../../sample/callbacks/sample_callbacks'
|
|
7
|
-
|
|
8
|
-
class CallbacksTest < Minitest::Test
|
|
9
|
-
def test_callbacks_sample_lambda
|
|
10
|
-
cb = CallbackHolder.new
|
|
11
|
-
cb.register_callback(lambda do |param|
|
|
12
|
-
"Callback got: #{param}"
|
|
13
|
-
end)
|
|
14
|
-
|
|
15
|
-
assert_equal "Callback got: Hello", cb.fire_callback("Hello")
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def hello_world(param)
|
|
19
|
-
"Method got: #{param}"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def test_callbacks_sample_method
|
|
23
|
-
cb = CallbackHolder.new
|
|
24
|
-
cb.register_callback method(:hello_world)
|
|
25
|
-
|
|
26
|
-
assert_equal "Method got: Hello", cb.fire_callback("Hello")
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
$: << File.join(__dir__, '..', '..', 'sample')
|
|
2
|
-
|
|
3
|
-
require 'minitest'
|
|
4
|
-
require 'minitest/autorun'
|
|
5
|
-
|
|
6
|
-
class MultipleExtensionTest < Minitest::Test
|
|
7
|
-
def test_multiple_extensions
|
|
8
|
-
# Rinse
|
|
9
|
-
require 'map/map'
|
|
10
|
-
m = Std::Map.new
|
|
11
|
-
m[0] = 1
|
|
12
|
-
|
|
13
|
-
# And repeat
|
|
14
|
-
require 'enum/sample_enum'
|
|
15
|
-
m = Std::Map.new
|
|
16
|
-
m[0] = 1
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
$: << File.join(__dir__, '..', 'ext')
|
|
2
|
-
|
|
3
|
-
require 'minitest'
|
|
4
|
-
require 'minitest/autorun'
|
|
5
|
-
|
|
6
|
-
class MultipleExtensionsSameClassTest < Minitest::Test
|
|
7
|
-
def test_multiple_extensions_same_class
|
|
8
|
-
require 't1/t1'
|
|
9
|
-
require 't2/t2'
|
|
10
|
-
|
|
11
|
-
foo = Foo.new
|
|
12
|
-
assert_equal 42, foo.foo
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
$: << File.join(__dir__, '..', '..', 'sample')
|
|
2
|
-
# Load a library that uses inheritance
|
|
3
|
-
require 'inheritance/animals'
|
|
4
|
-
|
|
5
|
-
# Then load a different library
|
|
6
|
-
require 'enum/sample_enum'
|
|
7
|
-
|
|
8
|
-
require 'minitest'
|
|
9
|
-
require 'minitest/autorun'
|
|
10
|
-
|
|
11
|
-
class MultipleExtensionTest < Minitest::Test
|
|
12
|
-
def test_multiple_extensions_with_inheritance
|
|
13
|
-
|
|
14
|
-
# And make sure we can call methods in the base class on a derived
|
|
15
|
-
# instance
|
|
16
|
-
dog = Dog.new
|
|
17
|
-
assert_equal dog.name, "Dog"
|
|
18
|
-
assert_equal dog.speak, "Woof woof"
|
|
19
|
-
end
|
|
20
|
-
end
|
|
File without changes
|