rucy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +12 -0
- data/README +4 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/ext/rucy/extconf.rb +50 -0
- data/ext/rucy/tester.cpp +102 -0
- data/include/rucy/class.h +37 -0
- data/include/rucy/defs.h +97 -0
- data/include/rucy/defs.h.erb +56 -0
- data/include/rucy/exception.h +124 -0
- data/include/rucy/function.h +245 -0
- data/include/rucy/function.h.erb +73 -0
- data/include/rucy/gc.h +59 -0
- data/include/rucy/module.h +96 -0
- data/include/rucy/module.h.erb +68 -0
- data/include/rucy/rucy.h +64 -0
- data/include/rucy/string.h +28 -0
- data/include/rucy/symbol.h +50 -0
- data/include/rucy/value.h +291 -0
- data/include/rucy/value.h.erb +278 -0
- data/include/rucy.h +10 -0
- data/lib/rucy.rb +24 -0
- data/rucy.gemspec +50 -0
- data/src/class.cpp +35 -0
- data/src/exception.cpp +124 -0
- data/src/function.cpp +157 -0
- data/src/function.cpp.erb +74 -0
- data/src/gc.cpp +63 -0
- data/src/module.cpp +321 -0
- data/src/module.cpp.erb +103 -0
- data/src/rucy.cpp +56 -0
- data/src/string.cpp +78 -0
- data/src/symbol.cpp +51 -0
- data/src/value.cpp +511 -0
- data/src/value.cpp.erb +409 -0
- data/support.rb +58 -0
- data/task/ext.rake +36 -0
- data/task/gem.rake +33 -0
- data/task/lib.rake +47 -0
- data/test/test_rucy.rb +57 -0
- metadata +116 -0
@@ -0,0 +1,291 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RUCY_VALUE_H__
|
4
|
+
#define __RUCY_VALUE_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <ruby.h>
|
8
|
+
#include <rucy/symbol.h>
|
9
|
+
|
10
|
+
|
11
|
+
namespace Rucy
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
class Value
|
16
|
+
{
|
17
|
+
|
18
|
+
public:
|
19
|
+
|
20
|
+
Value ();
|
21
|
+
|
22
|
+
Value (bool b);
|
23
|
+
|
24
|
+
Value (int i);
|
25
|
+
|
26
|
+
Value (float f);
|
27
|
+
|
28
|
+
Value (double d);
|
29
|
+
|
30
|
+
Value (const char* s, bool tainted = false);
|
31
|
+
|
32
|
+
Value (const char* s, size_t len, bool tainted = false);
|
33
|
+
|
34
|
+
Value (size_t size, const Value* values);
|
35
|
+
|
36
|
+
Value (VALUE v);
|
37
|
+
|
38
|
+
VALUE value () const;
|
39
|
+
|
40
|
+
void mark () const;
|
41
|
+
|
42
|
+
int type () const;
|
43
|
+
|
44
|
+
Value klass () const;
|
45
|
+
|
46
|
+
bool is_kind_of (Value klass) const;
|
47
|
+
|
48
|
+
int size () const;
|
49
|
+
|
50
|
+
int length () const;
|
51
|
+
|
52
|
+
Value to_i () const;
|
53
|
+
|
54
|
+
Value to_f () const;
|
55
|
+
|
56
|
+
Value to_s () const;
|
57
|
+
|
58
|
+
Value to_sym () const;
|
59
|
+
|
60
|
+
bool is_i () const;
|
61
|
+
|
62
|
+
bool is_f () const;
|
63
|
+
|
64
|
+
bool is_s () const;
|
65
|
+
|
66
|
+
bool is_sym () const;
|
67
|
+
|
68
|
+
bool is_a () const;
|
69
|
+
|
70
|
+
int as_i (bool convert = false) const;
|
71
|
+
|
72
|
+
double as_f (bool convert = false) const;
|
73
|
+
|
74
|
+
const char* as_s (bool convert = false) const;
|
75
|
+
|
76
|
+
Symbol as_sym (bool convert = false) const;
|
77
|
+
|
78
|
+
Value call (Symbol name, int argc, const Value* argv) const;
|
79
|
+
Value call (Symbol name) const;
|
80
|
+
Value call (Symbol name, Value v1) const;
|
81
|
+
Value call (Symbol name, Value v1, Value v2) const;
|
82
|
+
Value call (Symbol name, Value v1, Value v2, Value v3) const;
|
83
|
+
Value call (Symbol name, Value v1, Value v2, Value v3, Value v4) const;
|
84
|
+
Value call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5) const;
|
85
|
+
Value call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6) const;
|
86
|
+
Value call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6, Value v7) const;
|
87
|
+
Value call (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6, Value v7, Value v8) const;
|
88
|
+
Value operator () (Symbol name, int argc, const Value* argv) const;
|
89
|
+
Value operator () (Symbol name) const;
|
90
|
+
Value operator () (Symbol name, Value v1) const;
|
91
|
+
Value operator () (Symbol name, Value v1, Value v2) const;
|
92
|
+
Value operator () (Symbol name, Value v1, Value v2, Value v3) const;
|
93
|
+
Value operator () (Symbol name, Value v1, Value v2, Value v3, Value v4) const;
|
94
|
+
Value operator () (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5) const;
|
95
|
+
Value operator () (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6) const;
|
96
|
+
Value operator () (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6, Value v7) const;
|
97
|
+
Value operator () (Symbol name, Value v1, Value v2, Value v3, Value v4, Value v5, Value v6, Value v7, Value v8) const;
|
98
|
+
|
99
|
+
Value inspect () const;
|
100
|
+
|
101
|
+
const char* c_str () const;
|
102
|
+
|
103
|
+
Value& operator [] (int i);
|
104
|
+
|
105
|
+
const Value& operator [] (int i) const;
|
106
|
+
|
107
|
+
operator VALUE () const;
|
108
|
+
|
109
|
+
operator bool () const;
|
110
|
+
|
111
|
+
bool operator ! () const;
|
112
|
+
|
113
|
+
bool operator == (const Value& rhs) const;
|
114
|
+
|
115
|
+
bool operator != (const Value& rhs) const;
|
116
|
+
|
117
|
+
// Array
|
118
|
+
|
119
|
+
Value push (Value obj);
|
120
|
+
|
121
|
+
Value pop ();
|
122
|
+
|
123
|
+
Value shift ();
|
124
|
+
|
125
|
+
Value unshift (Value obj);
|
126
|
+
|
127
|
+
private:
|
128
|
+
|
129
|
+
VALUE v;
|
130
|
+
|
131
|
+
friend class GCGuard;
|
132
|
+
|
133
|
+
};// Value
|
134
|
+
|
135
|
+
|
136
|
+
Value value (bool b);
|
137
|
+
|
138
|
+
Value value (char c);
|
139
|
+
|
140
|
+
Value value (unsigned char c);
|
141
|
+
|
142
|
+
Value value (short s);
|
143
|
+
|
144
|
+
Value value (unsigned short s);
|
145
|
+
|
146
|
+
Value value (int i);
|
147
|
+
|
148
|
+
Value value (unsigned int i);
|
149
|
+
|
150
|
+
Value value (long l);
|
151
|
+
|
152
|
+
Value value (unsigned long l);
|
153
|
+
|
154
|
+
Value value (long long ll);
|
155
|
+
|
156
|
+
Value value (unsigned long long ll);
|
157
|
+
|
158
|
+
Value value (float f);
|
159
|
+
|
160
|
+
Value value (double d);
|
161
|
+
|
162
|
+
Value value (const char* s, bool tainted = false);
|
163
|
+
|
164
|
+
Value value (const char* s, size_t len, bool tainted = false);
|
165
|
+
|
166
|
+
Value value (size_t size, const Value* values);
|
167
|
+
|
168
|
+
Value value (Symbol sym);
|
169
|
+
|
170
|
+
|
171
|
+
template <typename T> T value_to (Value obj, bool convert = true);
|
172
|
+
|
173
|
+
template <> inline bool
|
174
|
+
value_to<bool> (Value obj, bool convert)
|
175
|
+
{
|
176
|
+
return (bool) obj;
|
177
|
+
}
|
178
|
+
|
179
|
+
template <> inline int
|
180
|
+
value_to<int> (Value obj, bool convert)
|
181
|
+
{
|
182
|
+
if (convert) obj = obj.to_i();
|
183
|
+
return NUM2INT(obj.value());
|
184
|
+
}
|
185
|
+
|
186
|
+
template <> inline unsigned int
|
187
|
+
value_to<unsigned int> (Value obj, bool convert)
|
188
|
+
{
|
189
|
+
if (convert) obj = obj.to_i();
|
190
|
+
return NUM2UINT(obj.value());
|
191
|
+
}
|
192
|
+
|
193
|
+
template <> inline char
|
194
|
+
value_to<char> (Value obj, bool convert)
|
195
|
+
{
|
196
|
+
return (char) value_to<int>(obj, convert);
|
197
|
+
}
|
198
|
+
|
199
|
+
template <> inline unsigned char
|
200
|
+
value_to<unsigned char> (Value obj, bool convert)
|
201
|
+
{
|
202
|
+
return (unsigned char) value_to<int>(obj, convert);
|
203
|
+
}
|
204
|
+
|
205
|
+
template <> inline short
|
206
|
+
value_to<short> (Value obj, bool convert)
|
207
|
+
{
|
208
|
+
return (short) value_to<int>(obj, convert);
|
209
|
+
}
|
210
|
+
|
211
|
+
template <> inline unsigned short
|
212
|
+
value_to<unsigned short> (Value obj, bool convert)
|
213
|
+
{
|
214
|
+
return (unsigned short) value_to<int>(obj, convert);
|
215
|
+
}
|
216
|
+
|
217
|
+
template <> inline long
|
218
|
+
value_to<long> (Value obj, bool convert)
|
219
|
+
{
|
220
|
+
if (convert) obj = obj.to_i();
|
221
|
+
return NUM2LONG(obj.value());
|
222
|
+
}
|
223
|
+
|
224
|
+
template <> inline unsigned long
|
225
|
+
value_to<unsigned long> (Value obj, bool convert)
|
226
|
+
{
|
227
|
+
if (convert) obj = obj.to_i();
|
228
|
+
return NUM2ULONG(obj.value());
|
229
|
+
}
|
230
|
+
|
231
|
+
template <> inline long long
|
232
|
+
value_to<long long> (Value obj, bool convert)
|
233
|
+
{
|
234
|
+
if (convert) obj = obj.to_i();
|
235
|
+
return NUM2LL(obj.value());
|
236
|
+
}
|
237
|
+
|
238
|
+
template <> inline unsigned long long
|
239
|
+
value_to<unsigned long long> (Value obj, bool convert)
|
240
|
+
{
|
241
|
+
if (convert) obj = obj.to_i();
|
242
|
+
return NUM2ULL(obj.value());
|
243
|
+
}
|
244
|
+
|
245
|
+
template <> inline double
|
246
|
+
value_to<double> (Value obj, bool convert)
|
247
|
+
{
|
248
|
+
if (convert) obj = obj.to_f();
|
249
|
+
Check_Type(obj, T_FLOAT);
|
250
|
+
return RFLOAT_VALUE(obj.value());
|
251
|
+
}
|
252
|
+
|
253
|
+
template <> inline float
|
254
|
+
value_to<float> (Value obj, bool convert)
|
255
|
+
{
|
256
|
+
return (float) value_to<double>(obj, convert);
|
257
|
+
}
|
258
|
+
|
259
|
+
template <> inline char*
|
260
|
+
value_to<char*> (Value obj, bool convert)
|
261
|
+
{
|
262
|
+
if (convert) obj = obj.to_s();
|
263
|
+
VALUE s = obj.value();
|
264
|
+
return StringValueCStr(s);
|
265
|
+
}
|
266
|
+
|
267
|
+
template <> inline const char*
|
268
|
+
value_to<const char*> (Value obj, bool convert)
|
269
|
+
{
|
270
|
+
return value_to<char*>(obj, convert);
|
271
|
+
}
|
272
|
+
|
273
|
+
template <> inline Symbol
|
274
|
+
value_to<Symbol> (Value obj, bool convert)
|
275
|
+
{
|
276
|
+
if (convert) obj = obj.to_sym();
|
277
|
+
Check_Type(obj, T_SYMBOL);
|
278
|
+
return SYM2ID(obj.value());
|
279
|
+
}
|
280
|
+
|
281
|
+
|
282
|
+
template <typename T> inline T to (Value obj, bool convert = true)
|
283
|
+
{
|
284
|
+
return value_to<T>(obj, convert);
|
285
|
+
}
|
286
|
+
|
287
|
+
|
288
|
+
}// Rucy
|
289
|
+
|
290
|
+
|
291
|
+
#endif//EOH
|
@@ -0,0 +1,278 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
% require 'support'
|
3
|
+
#pragma once
|
4
|
+
#ifndef __RUCY_VALUE_H__
|
5
|
+
#define __RUCY_VALUE_H__
|
6
|
+
|
7
|
+
|
8
|
+
#include <ruby.h>
|
9
|
+
#include <rucy/symbol.h>
|
10
|
+
|
11
|
+
|
12
|
+
namespace Rucy
|
13
|
+
{
|
14
|
+
|
15
|
+
|
16
|
+
class Value
|
17
|
+
{
|
18
|
+
|
19
|
+
public:
|
20
|
+
|
21
|
+
Value ();
|
22
|
+
|
23
|
+
Value (bool b);
|
24
|
+
|
25
|
+
Value (int i);
|
26
|
+
|
27
|
+
Value (float f);
|
28
|
+
|
29
|
+
Value (double d);
|
30
|
+
|
31
|
+
Value (const char* s, bool tainted = false);
|
32
|
+
|
33
|
+
Value (const char* s, size_t len, bool tainted = false);
|
34
|
+
|
35
|
+
Value (size_t size, const Value* values);
|
36
|
+
|
37
|
+
Value (VALUE v);
|
38
|
+
|
39
|
+
VALUE value () const;
|
40
|
+
|
41
|
+
void mark () const;
|
42
|
+
|
43
|
+
int type () const;
|
44
|
+
|
45
|
+
Value klass () const;
|
46
|
+
|
47
|
+
bool is_kind_of (Value klass) const;
|
48
|
+
|
49
|
+
int size () const;
|
50
|
+
|
51
|
+
int length () const;
|
52
|
+
|
53
|
+
Value to_i () const;
|
54
|
+
|
55
|
+
Value to_f () const;
|
56
|
+
|
57
|
+
Value to_s () const;
|
58
|
+
|
59
|
+
Value to_sym () const;
|
60
|
+
|
61
|
+
bool is_i () const;
|
62
|
+
|
63
|
+
bool is_f () const;
|
64
|
+
|
65
|
+
bool is_s () const;
|
66
|
+
|
67
|
+
bool is_sym () const;
|
68
|
+
|
69
|
+
bool is_a () const;
|
70
|
+
|
71
|
+
int as_i (bool convert = false) const;
|
72
|
+
|
73
|
+
double as_f (bool convert = false) const;
|
74
|
+
|
75
|
+
const char* as_s (bool convert = false) const;
|
76
|
+
|
77
|
+
Symbol as_sym (bool convert = false) const;
|
78
|
+
|
79
|
+
% ["call", "operator ()"].each do |op|
|
80
|
+
Value <%= op %> (Symbol name, int argc, const Value* argv) const;
|
81
|
+
% NTIMES.each do |n|
|
82
|
+
Value <%= op %> (Symbol name<%= params(n) {|i| ", Value v#{i}"} %>) const;
|
83
|
+
% end
|
84
|
+
% end
|
85
|
+
|
86
|
+
Value inspect () const;
|
87
|
+
|
88
|
+
const char* c_str () const;
|
89
|
+
|
90
|
+
Value& operator [] (int i);
|
91
|
+
|
92
|
+
const Value& operator [] (int i) const;
|
93
|
+
|
94
|
+
operator VALUE () const;
|
95
|
+
|
96
|
+
operator bool () const;
|
97
|
+
|
98
|
+
bool operator ! () const;
|
99
|
+
|
100
|
+
bool operator == (const Value& rhs) const;
|
101
|
+
|
102
|
+
bool operator != (const Value& rhs) const;
|
103
|
+
|
104
|
+
// Array
|
105
|
+
|
106
|
+
Value push (Value obj);
|
107
|
+
|
108
|
+
Value pop ();
|
109
|
+
|
110
|
+
Value shift ();
|
111
|
+
|
112
|
+
Value unshift (Value obj);
|
113
|
+
|
114
|
+
private:
|
115
|
+
|
116
|
+
VALUE v;
|
117
|
+
|
118
|
+
friend class GCGuard;
|
119
|
+
|
120
|
+
};// Value
|
121
|
+
|
122
|
+
|
123
|
+
Value value (bool b);
|
124
|
+
|
125
|
+
Value value (char c);
|
126
|
+
|
127
|
+
Value value (unsigned char c);
|
128
|
+
|
129
|
+
Value value (short s);
|
130
|
+
|
131
|
+
Value value (unsigned short s);
|
132
|
+
|
133
|
+
Value value (int i);
|
134
|
+
|
135
|
+
Value value (unsigned int i);
|
136
|
+
|
137
|
+
Value value (long l);
|
138
|
+
|
139
|
+
Value value (unsigned long l);
|
140
|
+
|
141
|
+
Value value (long long ll);
|
142
|
+
|
143
|
+
Value value (unsigned long long ll);
|
144
|
+
|
145
|
+
Value value (float f);
|
146
|
+
|
147
|
+
Value value (double d);
|
148
|
+
|
149
|
+
Value value (const char* s, bool tainted = false);
|
150
|
+
|
151
|
+
Value value (const char* s, size_t len, bool tainted = false);
|
152
|
+
|
153
|
+
Value value (size_t size, const Value* values);
|
154
|
+
|
155
|
+
Value value (Symbol sym);
|
156
|
+
|
157
|
+
|
158
|
+
template <typename T> T value_to (Value obj, bool convert = true);
|
159
|
+
|
160
|
+
template <> inline bool
|
161
|
+
value_to<bool> (Value obj, bool convert)
|
162
|
+
{
|
163
|
+
return (bool) obj;
|
164
|
+
}
|
165
|
+
|
166
|
+
template <> inline int
|
167
|
+
value_to<int> (Value obj, bool convert)
|
168
|
+
{
|
169
|
+
if (convert) obj = obj.to_i();
|
170
|
+
return NUM2INT(obj.value());
|
171
|
+
}
|
172
|
+
|
173
|
+
template <> inline unsigned int
|
174
|
+
value_to<unsigned int> (Value obj, bool convert)
|
175
|
+
{
|
176
|
+
if (convert) obj = obj.to_i();
|
177
|
+
return NUM2UINT(obj.value());
|
178
|
+
}
|
179
|
+
|
180
|
+
template <> inline char
|
181
|
+
value_to<char> (Value obj, bool convert)
|
182
|
+
{
|
183
|
+
return (char) value_to<int>(obj, convert);
|
184
|
+
}
|
185
|
+
|
186
|
+
template <> inline unsigned char
|
187
|
+
value_to<unsigned char> (Value obj, bool convert)
|
188
|
+
{
|
189
|
+
return (unsigned char) value_to<int>(obj, convert);
|
190
|
+
}
|
191
|
+
|
192
|
+
template <> inline short
|
193
|
+
value_to<short> (Value obj, bool convert)
|
194
|
+
{
|
195
|
+
return (short) value_to<int>(obj, convert);
|
196
|
+
}
|
197
|
+
|
198
|
+
template <> inline unsigned short
|
199
|
+
value_to<unsigned short> (Value obj, bool convert)
|
200
|
+
{
|
201
|
+
return (unsigned short) value_to<int>(obj, convert);
|
202
|
+
}
|
203
|
+
|
204
|
+
template <> inline long
|
205
|
+
value_to<long> (Value obj, bool convert)
|
206
|
+
{
|
207
|
+
if (convert) obj = obj.to_i();
|
208
|
+
return NUM2LONG(obj.value());
|
209
|
+
}
|
210
|
+
|
211
|
+
template <> inline unsigned long
|
212
|
+
value_to<unsigned long> (Value obj, bool convert)
|
213
|
+
{
|
214
|
+
if (convert) obj = obj.to_i();
|
215
|
+
return NUM2ULONG(obj.value());
|
216
|
+
}
|
217
|
+
|
218
|
+
template <> inline long long
|
219
|
+
value_to<long long> (Value obj, bool convert)
|
220
|
+
{
|
221
|
+
if (convert) obj = obj.to_i();
|
222
|
+
return NUM2LL(obj.value());
|
223
|
+
}
|
224
|
+
|
225
|
+
template <> inline unsigned long long
|
226
|
+
value_to<unsigned long long> (Value obj, bool convert)
|
227
|
+
{
|
228
|
+
if (convert) obj = obj.to_i();
|
229
|
+
return NUM2ULL(obj.value());
|
230
|
+
}
|
231
|
+
|
232
|
+
template <> inline double
|
233
|
+
value_to<double> (Value obj, bool convert)
|
234
|
+
{
|
235
|
+
if (convert) obj = obj.to_f();
|
236
|
+
Check_Type(obj, T_FLOAT);
|
237
|
+
return RFLOAT_VALUE(obj.value());
|
238
|
+
}
|
239
|
+
|
240
|
+
template <> inline float
|
241
|
+
value_to<float> (Value obj, bool convert)
|
242
|
+
{
|
243
|
+
return (float) value_to<double>(obj, convert);
|
244
|
+
}
|
245
|
+
|
246
|
+
template <> inline char*
|
247
|
+
value_to<char*> (Value obj, bool convert)
|
248
|
+
{
|
249
|
+
if (convert) obj = obj.to_s();
|
250
|
+
VALUE s = obj.value();
|
251
|
+
return StringValueCStr(s);
|
252
|
+
}
|
253
|
+
|
254
|
+
template <> inline const char*
|
255
|
+
value_to<const char*> (Value obj, bool convert)
|
256
|
+
{
|
257
|
+
return value_to<char*>(obj, convert);
|
258
|
+
}
|
259
|
+
|
260
|
+
template <> inline Symbol
|
261
|
+
value_to<Symbol> (Value obj, bool convert)
|
262
|
+
{
|
263
|
+
if (convert) obj = obj.to_sym();
|
264
|
+
Check_Type(obj, T_SYMBOL);
|
265
|
+
return SYM2ID(obj.value());
|
266
|
+
}
|
267
|
+
|
268
|
+
|
269
|
+
template <typename T> inline T to (Value obj, bool convert = true)
|
270
|
+
{
|
271
|
+
return value_to<T>(obj, convert);
|
272
|
+
}
|
273
|
+
|
274
|
+
|
275
|
+
}// Rucy
|
276
|
+
|
277
|
+
|
278
|
+
#endif//EOH
|
data/include/rucy.h
ADDED
data/lib/rucy.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
module Rucy
|
5
|
+
|
6
|
+
|
7
|
+
def self.root_dir ()
|
8
|
+
File.expand_path(File.join File.dirname(__FILE__), '..')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.include_dirs ()
|
12
|
+
[File.join(root_dir, 'include')]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.library_dirs ()
|
16
|
+
[File.join(root_dir, 'lib')]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.version ()
|
20
|
+
open(File.join root_dir, 'VERSION') {|f| f.readline.chomp}
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
end# Rucy
|
data/rucy.gemspec
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
+
$: << File.join(File.dirname(__FILE__), 'lib')
|
3
|
+
require 'rake'
|
4
|
+
require 'rucy'
|
5
|
+
|
6
|
+
|
7
|
+
FILES = FileList[*%w[
|
8
|
+
README
|
9
|
+
Rakefile
|
10
|
+
Gemfile
|
11
|
+
Gemfile.lock
|
12
|
+
support.rb
|
13
|
+
rucy.gemspec
|
14
|
+
VERSION
|
15
|
+
task/**/*.rake
|
16
|
+
ext/**/*.rb
|
17
|
+
ext/**/*.cpp
|
18
|
+
include/**/*.h
|
19
|
+
include/**/*.erb
|
20
|
+
lib/**/*.rb
|
21
|
+
src/**/*.cpp
|
22
|
+
src/**/*.erb
|
23
|
+
test/**/*.rb
|
24
|
+
]]
|
25
|
+
|
26
|
+
Gem::Specification.new do |s|
|
27
|
+
s.name = 'rucy'
|
28
|
+
s.summary = 'A Ruby C++ Extension Helper Library.'
|
29
|
+
s.description = 'This library helps you to develop Ruby Extension by C++.'
|
30
|
+
s.version = Rucy.version
|
31
|
+
|
32
|
+
s.authors = %w[@tokujiros]
|
33
|
+
s.email = 'tokujiros@gmail.com'
|
34
|
+
s.homepage = 'http://xord.tumblr.com/'
|
35
|
+
|
36
|
+
s.platform = Gem::Platform::RUBY
|
37
|
+
s.required_ruby_version = '>=1.9.0'
|
38
|
+
s.require_paths << 'ext'
|
39
|
+
|
40
|
+
s.add_dependency 'rake'
|
41
|
+
s.add_development_dependency 'gemcutter'
|
42
|
+
|
43
|
+
s.files = FILES.to_a
|
44
|
+
s.test_files = FileList['test/**/test_*.rb'].to_a
|
45
|
+
|
46
|
+
s.has_rdoc = true
|
47
|
+
s.extra_rdoc_files = ['README']
|
48
|
+
|
49
|
+
s.extensions << 'Rakefile'
|
50
|
+
end
|
data/src/class.cpp
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#include "rucy/class.h"
|
3
|
+
|
4
|
+
|
5
|
+
namespace Rucy
|
6
|
+
{
|
7
|
+
|
8
|
+
|
9
|
+
Class::Class (VALUE v)
|
10
|
+
: Super(v)
|
11
|
+
{
|
12
|
+
}
|
13
|
+
|
14
|
+
Class
|
15
|
+
Class::define_alloc_func (RubyFunction0 fun)
|
16
|
+
{
|
17
|
+
rb_define_alloc_func(value(), (VALUE(*)(VALUE)) fun);
|
18
|
+
return *this;
|
19
|
+
}
|
20
|
+
|
21
|
+
Class
|
22
|
+
Class::define_alloc_func (const char*, RubyFunction0 fun)
|
23
|
+
{
|
24
|
+
return define_alloc_func(fun);
|
25
|
+
}
|
26
|
+
|
27
|
+
|
28
|
+
Class
|
29
|
+
define_class (const char* name, Value super)
|
30
|
+
{
|
31
|
+
return rb_define_class(name, super);
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
}// Rucy
|