extpp 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ check_debug_build: checking --enable-debug-build option... -------------------- no
2
+
3
+ --------------------
4
+
5
+ check_version: checking g++ version... -------------------- 7.3
6
+
7
+ --------------------
8
+
@@ -3,76 +3,100 @@
3
3
  extern "C" void
4
4
  Init_object(void)
5
5
  {
6
- rb::Class("ObjectMethods").
7
- define_method("to_bool_true", [](VALUE self) {
8
- rb::Object object(Qtrue);
9
- if (object) {
10
- return Qtrue;
11
- } else {
12
- return Qfalse;
13
- }
14
- }).
15
- define_method("to_bool_false", [](VALUE self) {
16
- rb::Object object(Qfalse);
17
- if (object) {
18
- return Qtrue;
19
- } else {
20
- return Qfalse;
21
- }
22
- }).
23
- define_method("to_bool_nil", [](VALUE self) {
24
- rb::Object object(Qnil);
25
- if (object) {
26
- return Qtrue;
27
- } else {
28
- return Qfalse;
29
- }
30
- }).
31
- define_method("to_ruby", [](int argc, VALUE *argv, VALUE self) {
32
- VALUE rb_object;
33
- rb_scan_args(argc, argv, "1", &rb_object);
34
- rb::Object object(rb_object);
35
- return static_cast<VALUE>(object);
36
- }).
37
- define_method("send_no_arguments", [](int argc, VALUE *argv, VALUE self) {
38
- VALUE rb_receiver;
39
- VALUE rb_method_name;
40
- rb_scan_args(argc, argv, "2", &rb_receiver, &rb_method_name);
41
- rb::Object receiver(rb_receiver);
42
- rb::Object method_name(rb_method_name);
43
- auto result = receiver.send(method_name);
44
- return static_cast<VALUE>(result);
45
- }).
46
- define_method("send_two_arguments", [](int argc, VALUE *argv, VALUE self) {
47
- VALUE rb_receiver;
48
- VALUE rb_method_name;
49
- VALUE rb_arg1;
50
- VALUE rb_arg2;
51
- rb_scan_args(argc, argv, "4",
52
- &rb_receiver,
53
- &rb_method_name,
54
- &rb_arg1,
55
- &rb_arg2);
56
- rb::Object receiver(rb_receiver);
57
- rb::Object method_name(rb_method_name);
58
- auto result = receiver.send(method_name, {rb_arg1, rb_arg2});
59
- return static_cast<VALUE>(result);
60
- }).
61
- define_method("send_block", [](int argc, VALUE *argv, VALUE self) {
62
- VALUE rb_receiver;
63
- VALUE rb_method_name;
64
- rb_scan_args(argc, argv, "2",
65
- &rb_receiver,
66
- &rb_method_name);
67
- rb::Object receiver(rb_receiver);
68
- rb::Object method_name(rb_method_name);
69
- auto result = receiver.send(method_name,
70
- {},
71
- [](VALUE rb_n) -> VALUE {
72
- auto n = rb::Object(rb_n);
73
- auto n_raw = rb::cast<int32_t>(n);
74
- return rb::cast<rb::Object>(n_raw * n_raw);
75
- });
76
- return static_cast<VALUE>(result);
77
- });
6
+ rb::Class klass("ObjectMethods");
7
+ klass.define_method("to_bool_true", [](VALUE self) {
8
+ rb::Object object(Qtrue);
9
+ if (object) {
10
+ return Qtrue;
11
+ } else {
12
+ return Qfalse;
13
+ }
14
+ });
15
+ klass.define_method("to_bool_false", [](VALUE self) {
16
+ rb::Object object(Qfalse);
17
+ if (object) {
18
+ return Qtrue;
19
+ } else {
20
+ return Qfalse;
21
+ }
22
+ });
23
+ klass.define_method("to_bool_nil", [](VALUE self) {
24
+ rb::Object object(Qnil);
25
+ if (object) {
26
+ return Qtrue;
27
+ } else {
28
+ return Qfalse;
29
+ }
30
+ });
31
+ klass.define_method("to_ruby", [](int argc, VALUE *argv, VALUE self) {
32
+ VALUE rb_object;
33
+ rb_scan_args(argc, argv, "1", &rb_object);
34
+ rb::Object object(rb_object);
35
+ return static_cast<VALUE>(object);
36
+ });
37
+ klass.define_method("send_no_arguments", [](int argc, VALUE *argv, VALUE self) {
38
+ VALUE rb_receiver;
39
+ VALUE rb_method_name;
40
+ rb_scan_args(argc, argv, "2", &rb_receiver, &rb_method_name);
41
+ rb::Object receiver(rb_receiver);
42
+ rb::Object method_name(rb_method_name);
43
+ auto result = receiver.send(method_name);
44
+ return static_cast<VALUE>(result);
45
+ });
46
+ klass.define_method("send_two_arguments", [](int argc, VALUE *argv, VALUE self) {
47
+ VALUE rb_receiver;
48
+ VALUE rb_method_name;
49
+ VALUE rb_arg1;
50
+ VALUE rb_arg2;
51
+ rb_scan_args(argc, argv, "4",
52
+ &rb_receiver,
53
+ &rb_method_name,
54
+ &rb_arg1,
55
+ &rb_arg2);
56
+ rb::Object receiver(rb_receiver);
57
+ rb::Object method_name(rb_method_name);
58
+ auto result = receiver.send(method_name, {rb_arg1, rb_arg2});
59
+ return static_cast<VALUE>(result);
60
+ });
61
+ klass.define_method("send_block", [](int argc, VALUE *argv, VALUE self) {
62
+ VALUE rb_receiver;
63
+ VALUE rb_method_name;
64
+ rb_scan_args(argc, argv, "2",
65
+ &rb_receiver,
66
+ &rb_method_name);
67
+ rb::Object receiver(rb_receiver);
68
+ rb::Object method_name(rb_method_name);
69
+ auto result = receiver.send(method_name,
70
+ {},
71
+ [](VALUE rb_n) -> VALUE {
72
+ auto n = rb::Object(rb_n);
73
+ auto n_raw = rb::cast<int32_t>(n);
74
+ return rb::cast<rb::Object>(n_raw * n_raw);
75
+ });
76
+ return static_cast<VALUE>(result);
77
+ });
78
+ klass.define_method("ivar_set", [](int argc, VALUE *argv, VALUE self) {
79
+ VALUE rb_receiver;
80
+ VALUE rb_name;
81
+ VALUE rb_value;
82
+ rb_scan_args(argc, argv, "3",
83
+ &rb_receiver,
84
+ &rb_name,
85
+ &rb_value);
86
+ rb::Object receiver(rb_receiver);
87
+ rb::Object name(rb_name);
88
+ auto result = receiver.ivar_set(name, rb_value);
89
+ return static_cast<VALUE>(result);
90
+ });
91
+ klass.define_method("ivar_get", [](int argc, VALUE *argv, VALUE self) {
92
+ VALUE rb_receiver;
93
+ VALUE rb_name;
94
+ rb_scan_args(argc, argv, "2",
95
+ &rb_receiver,
96
+ &rb_name);
97
+ rb::Object receiver(rb_receiver);
98
+ rb::Object name(rb_name);
99
+ auto result = receiver.ivar_get(name);
100
+ return static_cast<VALUE>(result);
101
+ });
78
102
  }
Binary file
Binary file
data/test/test-object.rb CHANGED
@@ -49,4 +49,20 @@ class ObjectTest < Test::Unit::TestCase
49
49
  ObjectMethods.new.send_block([1, 2, 3], "collect"))
50
50
  end
51
51
  end
52
+
53
+ sub_test_case("instance variable") do
54
+ def test_set
55
+ object = Object.new
56
+ methods = ObjectMethods.new
57
+ assert_equal("me", methods.ivar_set(object, "@name", "me"))
58
+ assert_equal("me", object.instance_variable_get("@name"))
59
+ end
60
+
61
+ def test_get
62
+ object = Object.new
63
+ object.instance_variable_set("@name", "me")
64
+ methods = ObjectMethods.new
65
+ assert_equal("me", methods.ivar_get(object, "@name"))
66
+ end
67
+ end
52
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extpp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
@@ -111,6 +111,7 @@ files:
111
111
  - ext/extpp/class.cpp
112
112
  - ext/extpp/extconf.rb
113
113
  - ext/extpp/function.cpp
114
+ - ext/extpp/function.hpp
114
115
  - ext/extpp/object.cpp
115
116
  - include/ruby.hpp
116
117
  - include/ruby/cast.hpp
@@ -120,12 +121,27 @@ files:
120
121
  - lib/extpp.rb
121
122
  - lib/extpp/compiler.rb
122
123
  - lib/extpp/version.rb
124
+ - sample/hello/Rakefile
125
+ - sample/hello/extconf.rb
126
+ - sample/hello/hello.cpp
127
+ - test/fixtures/cast/Makefile
123
128
  - test/fixtures/cast/cast.cpp
129
+ - test/fixtures/cast/cast.o
130
+ - test/fixtures/cast/cast.so
124
131
  - test/fixtures/cast/extconf.rb
132
+ - test/fixtures/cast/mkmf.log
133
+ - test/fixtures/class/Makefile
125
134
  - test/fixtures/class/class.cpp
135
+ - test/fixtures/class/class.o
136
+ - test/fixtures/class/class.so
126
137
  - test/fixtures/class/extconf.rb
138
+ - test/fixtures/class/mkmf.log
139
+ - test/fixtures/object/Makefile
127
140
  - test/fixtures/object/extconf.rb
141
+ - test/fixtures/object/mkmf.log
128
142
  - test/fixtures/object/object.cpp
143
+ - test/fixtures/object/object.o
144
+ - test/fixtures/object/object.so
129
145
  - test/helper.rb
130
146
  - test/run-test.rb
131
147
  - test/test-cast.rb
@@ -161,9 +177,21 @@ test_files:
161
177
  - test/test-object.rb
162
178
  - test/test-class.rb
163
179
  - test/test-cast.rb
180
+ - test/fixtures/object/object.o
181
+ - test/fixtures/object/object.so
164
182
  - test/fixtures/object/object.cpp
183
+ - test/fixtures/object/mkmf.log
184
+ - test/fixtures/object/Makefile
165
185
  - test/fixtures/object/extconf.rb
186
+ - test/fixtures/cast/mkmf.log
187
+ - test/fixtures/cast/Makefile
166
188
  - test/fixtures/cast/extconf.rb
167
189
  - test/fixtures/cast/cast.cpp
190
+ - test/fixtures/cast/cast.so
191
+ - test/fixtures/cast/cast.o
192
+ - test/fixtures/class/class.so
193
+ - test/fixtures/class/mkmf.log
194
+ - test/fixtures/class/Makefile
168
195
  - test/fixtures/class/extconf.rb
196
+ - test/fixtures/class/class.o
169
197
  - test/fixtures/class/class.cpp