rubypython 0.2.8 → 0.2.9
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.
- data/History.txt +4 -1
- data/Manifest.txt +16 -1
- data/PostInstall.txt +1 -1
- data/README.txt +7 -2
- data/config/hoe.rb +12 -12
- data/ext/rubypython_bridge/cbridge.c +92 -90
- data/ext/rubypython_bridge/cbridge.h +6 -16
- data/ext/rubypython_bridge/ptor.c +110 -56
- data/ext/rubypython_bridge/ptor.h +9 -25
- data/ext/rubypython_bridge/rp_blankobject.c +42 -0
- data/ext/rubypython_bridge/rp_blankobject.h +10 -0
- data/ext/rubypython_bridge/rp_class.c +56 -0
- data/ext/rubypython_bridge/rp_class.h +6 -0
- data/ext/rubypython_bridge/rp_error.c +14 -4
- data/ext/rubypython_bridge/rp_error.h +3 -1
- data/ext/rubypython_bridge/rp_function.c +31 -0
- data/ext/rubypython_bridge/rp_function.h +6 -0
- data/ext/rubypython_bridge/rp_instance.c +165 -0
- data/ext/rubypython_bridge/rp_instance.h +6 -0
- data/ext/rubypython_bridge/rp_module.c +159 -0
- data/ext/rubypython_bridge/rp_module.h +7 -0
- data/ext/rubypython_bridge/rp_object.c +93 -427
- data/ext/rubypython_bridge/rp_object.h +8 -54
- data/ext/rubypython_bridge/rp_util.c +61 -0
- data/ext/rubypython_bridge/rp_util.h +11 -0
- data/ext/rubypython_bridge/rtop.c +103 -54
- data/ext/rubypython_bridge/rtop.h +11 -16
- data/ext/rubypython_bridge/rubypython_bridge.c +48 -20
- data/ext/rubypython_bridge/rubypython_bridge.h +5 -6
- data/lib/rubypython.rb +2 -2
- data/lib/rubypython/session.rb +4 -0
- data/lib/rubypython/version.rb +1 -1
- data/test/python_helpers/objects.py +12 -0
- data/test/python_helpers/objects.pyc +0 -0
- data/test/test_rubypython.rb +123 -19
- data/test/test_rubypython_bridge_extn.rb +52 -19
- data/test/test_session.rb +1 -1
- data/website/index.html +25 -9
- data/website/index.txt +26 -3
- metadata +20 -5
- data/.autotest +0 -9
@@ -1,47 +1,39 @@
|
|
1
1
|
#include "rp_object.h"
|
2
|
-
#include "stdio.h"
|
3
2
|
|
4
|
-
RUBY_EXTERN VALUE mRubyPythonBridge;
|
5
3
|
RUBY_EXTERN VALUE ePythonError;
|
4
|
+
RUBY_EXTERN VALUE mRubyPythonBridge;
|
5
|
+
RUBY_EXTERN VALUE cBlankObject;
|
6
6
|
|
7
|
-
VALUE
|
7
|
+
VALUE cRubyPyObject;
|
8
8
|
|
9
|
-
// :nodoc:
|
10
|
-
VALUE blank_undef_if(VALUE name,VALUE klass)
|
11
|
-
{
|
12
|
-
VALUE mname=rb_funcall(name,rb_intern("to_s"),0);
|
13
|
-
if(rb_funcall(mname,rb_intern("match"),1,rb_str_new2("(?:^__)|(?:\\?$)|(?:^send$)|(?:^class$)"))==Qnil)
|
14
|
-
{
|
15
|
-
rb_undef_method(klass,STR2CSTR(mname));
|
16
|
-
return Qtrue;
|
17
|
-
}
|
18
|
-
else
|
19
|
-
{
|
20
|
-
return Qfalse;
|
21
|
-
}
|
22
|
-
}
|
23
9
|
|
24
|
-
|
25
|
-
|
10
|
+
static void rpObjectMark(PObj*);
|
11
|
+
static void rpObjectFree(PObj*);
|
12
|
+
static VALUE rpObjectAlloc(VALUE);
|
13
|
+
|
14
|
+
//Create a new RubyPyObject
|
15
|
+
static
|
16
|
+
VALUE rpObjectAlloc(VALUE klass)
|
26
17
|
{
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
PObj* self = ALLOC(PObj);
|
19
|
+
self->pObject = NULL;
|
20
|
+
|
21
|
+
return Data_Wrap_Struct(klass, rpObjectMark, rpObjectFree, self);
|
30
22
|
}
|
31
23
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
VALUE cRubyPyFunction;
|
36
|
-
VALUE cRubyPyInstance;
|
37
|
-
|
38
|
-
void rp_obj_mark(PObj* self)
|
24
|
+
//Mark subsidiary objects for deletion
|
25
|
+
static
|
26
|
+
void rpObjectMark(PObj* self)
|
39
27
|
{}
|
40
28
|
|
41
|
-
|
29
|
+
//Delete a RubyPyObject
|
30
|
+
static
|
31
|
+
void rpObjectFree(PObj* self)
|
42
32
|
{
|
43
|
-
if(Py_IsInitialized()&&self->pObject)
|
33
|
+
if(Py_IsInitialized() && self->pObject)
|
44
34
|
{
|
35
|
+
//Make sure we decrement the object count on our wrapped
|
36
|
+
//object before we free the ruby wrapper
|
45
37
|
Py_XDECREF(self->pObject);
|
46
38
|
}
|
47
39
|
free(self);
|
@@ -53,66 +45,93 @@ Decreases the reference count on the object wrapped by this instance.
|
|
53
45
|
This is used for cleanup in RubyPython.stop. RubyPyObject instances automatically
|
54
46
|
decrease the reference count on their associated objects before they are garbage collected.
|
55
47
|
*/
|
56
|
-
|
48
|
+
static
|
49
|
+
VALUE rpObjectFreePobj(VALUE self)
|
57
50
|
{
|
58
51
|
PObj *cself;
|
59
|
-
|
60
|
-
|
52
|
+
|
53
|
+
Data_Get_Struct(self, PObj, cself);
|
54
|
+
|
55
|
+
if(Py_IsInitialized() && cself->pObject)
|
61
56
|
{
|
62
57
|
Py_XDECREF(cself->pObject);
|
63
|
-
cself->pObject=NULL;
|
58
|
+
cself->pObject = NULL;
|
64
59
|
return Qtrue;
|
65
60
|
}
|
66
61
|
else
|
67
62
|
{
|
68
|
-
cself->pObject=NULL;
|
63
|
+
cself->pObject = NULL;
|
69
64
|
}
|
65
|
+
|
70
66
|
return Qfalse;
|
71
67
|
}
|
72
68
|
|
73
|
-
|
74
|
-
|
75
|
-
PObj* self=ALLOC(PObj);
|
76
|
-
self->pObject=NULL;
|
77
|
-
return Data_Wrap_Struct(klass,rp_obj_mark,rp_obj_free,self);
|
78
|
-
}
|
79
|
-
|
80
|
-
|
81
|
-
PyObject* rp_obj_pobject(VALUE self)
|
69
|
+
//Fetchs the wrapped Python object from a RubyPyObject
|
70
|
+
PyObject* rpObjectGetPyObject(VALUE self)
|
82
71
|
{
|
83
72
|
PObj *cself;
|
84
|
-
|
73
|
+
|
74
|
+
Data_Get_Struct(self, PObj, cself);
|
75
|
+
|
85
76
|
if(!cself->pObject)
|
86
77
|
{
|
87
78
|
rb_raise(ePythonError,"RubyPython tried to access a freed object");
|
88
79
|
}
|
80
|
+
|
89
81
|
return cself->pObject;
|
90
82
|
}
|
91
83
|
|
84
|
+
|
85
|
+
//Creates a new RubyPyObject to wrap a python object
|
86
|
+
VALUE rpObjectFromPyObject
|
87
|
+
(PyObject* pObj)
|
88
|
+
{
|
89
|
+
PObj* self;
|
90
|
+
|
91
|
+
VALUE rObj = rb_class_new_instance(0, NULL, cRubyPyObject);
|
92
|
+
|
93
|
+
Data_Get_Struct(rObj, PObj, self);
|
94
|
+
|
95
|
+
self->pObject = pObj;
|
96
|
+
|
97
|
+
return rObj;
|
98
|
+
}
|
99
|
+
|
92
100
|
/*
|
93
101
|
Returns the name of the Python object which this instance wraps.
|
94
102
|
|
103
|
+
If it cannot determine a reasonable name it just gives up.
|
95
104
|
*/
|
96
|
-
|
105
|
+
static
|
106
|
+
VALUE rpObjectectGetName(VALUE self)
|
97
107
|
{
|
108
|
+
//It only makes sense to query a python object if the interpreter is running.
|
98
109
|
if(Py_IsInitialized())
|
99
110
|
{
|
100
111
|
PyObject *pObject,*pName,*pRepr;
|
101
112
|
VALUE rName;
|
102
|
-
|
103
|
-
|
113
|
+
|
114
|
+
pObject = rpObjectGetPyObject(self);
|
115
|
+
|
116
|
+
|
117
|
+
pName = PyObject_GetAttrString(pObject,"__name__");
|
118
|
+
|
104
119
|
if(!pName)
|
105
120
|
{
|
106
121
|
PyErr_Clear();
|
107
|
-
|
108
|
-
|
109
|
-
|
122
|
+
|
123
|
+
pName = PyObject_GetAttrString(pObject,"__class__");
|
124
|
+
pRepr = PyObject_Repr(pName);
|
125
|
+
rName = ptorString(pRepr);
|
110
126
|
Py_XDECREF(pRepr);
|
111
|
-
|
127
|
+
|
128
|
+
return rb_str_concat(rb_str_new2("An instance of "), rName);
|
112
129
|
if(!pName)
|
113
130
|
{
|
114
131
|
PyErr_Clear();
|
115
|
-
|
132
|
+
|
133
|
+
pName = PyObject_Repr(pObject);
|
134
|
+
|
116
135
|
if(!pName)
|
117
136
|
{
|
118
137
|
PyErr_Clear();
|
@@ -120,346 +139,41 @@ VALUE rp_obj_name(VALUE self)
|
|
120
139
|
}
|
121
140
|
}
|
122
141
|
}
|
123
|
-
rName=ptor_string(pName);
|
124
|
-
Py_XDECREF(pName);
|
125
|
-
return rName;
|
126
|
-
}
|
127
|
-
return rb_str_new2("__FREED__");
|
128
|
-
|
129
|
-
}
|
130
|
-
|
131
|
-
VALUE rp_obj_from_pyobject(PyObject *pObj)
|
132
|
-
{
|
133
|
-
PObj* self;
|
134
|
-
VALUE rObj=rb_class_new_instance(0,NULL,cRubyPyObject);
|
135
|
-
Data_Get_Struct(rObj,PObj,self);
|
136
|
-
self->pObject=pObj;
|
137
|
-
return rObj;
|
138
|
-
}
|
139
|
-
|
140
|
-
VALUE rp_inst_from_instance(PyObject *pInst)
|
141
|
-
{
|
142
|
-
PObj* self;
|
143
|
-
VALUE rInst=rb_class_new_instance(0,NULL,cRubyPyInstance);
|
144
|
-
PyObject *pClassDict,*pClass,*pInstDict;
|
145
|
-
VALUE rInstDict,rClassDict;
|
146
|
-
Data_Get_Struct(rInst,PObj,self);
|
147
|
-
self->pObject=pInst;
|
148
|
-
pClass=PyObject_GetAttrString(pInst,"__class__");
|
149
|
-
pClassDict=PyObject_GetAttrString(pClass,"__dict__");
|
150
|
-
pInstDict=PyObject_GetAttrString(pInst,"__dict__");
|
151
|
-
Py_XINCREF(pClassDict);
|
152
|
-
Py_XINCREF(pInstDict);
|
153
|
-
rClassDict=rp_obj_from_pyobject(pClassDict);
|
154
|
-
rInstDict=rp_obj_from_pyobject(pInstDict);
|
155
|
-
rb_iv_set(rInst,"@pclassdict",rClassDict);
|
156
|
-
rb_iv_set(rInst,"@pinstdict",rInstDict);
|
157
|
-
return rInst;
|
158
|
-
}
|
159
|
-
|
160
|
-
VALUE rp_inst_attr_set(VALUE self,VALUE args)
|
161
|
-
{
|
162
|
-
VALUE name,name_string,rClassDict,result,rInstDict;
|
163
|
-
VALUE ret;
|
164
|
-
int instance;
|
165
|
-
char *cname;
|
166
|
-
PObj *pClassDict,*pInstDict,*pDict;
|
167
|
-
PyObject *pName;
|
168
|
-
name=rb_ary_shift(args);
|
169
|
-
name_string=rb_funcall(name,rb_intern("to_s"),0);
|
170
|
-
rb_funcall(name_string,rb_intern("chop!"),0);
|
171
|
-
if(!rp_has_attr(self,name_string))
|
172
|
-
{
|
173
|
-
int argc;
|
174
|
-
VALUE *argv;
|
175
|
-
argc=RARRAY_LEN(args);
|
176
|
-
argv=ALLOC_N(VALUE,argc);
|
177
|
-
MEMCPY(argv,RARRAY_PTR(args),VALUE,argc);
|
178
|
-
return rb_call_super(argc,argv);
|
179
|
-
}
|
180
|
-
|
181
|
-
cname=STR2CSTR(name_string);
|
182
|
-
|
183
|
-
if((NUM2INT(rb_funcall(args,rb_intern("size"),0))==1))
|
184
|
-
{
|
185
|
-
args=rb_ary_entry(args,0);
|
186
|
-
}
|
187
|
-
|
188
142
|
|
189
|
-
|
190
|
-
rInstDict=rb_iv_get(self,"@pinstdict");
|
191
|
-
|
192
|
-
Data_Get_Struct(rClassDict,PObj,pClassDict);
|
193
|
-
Data_Get_Struct(rInstDict,PObj,pInstDict);
|
194
|
-
pName=PyString_FromString(cname);
|
195
|
-
if(PyDict_Contains(pInstDict->pObject,pName))
|
196
|
-
{
|
197
|
-
pDict=pInstDict;
|
198
|
-
|
199
|
-
}
|
200
|
-
else
|
201
|
-
{
|
202
|
-
pDict=pClassDict;
|
203
|
-
|
204
|
-
}
|
205
|
-
Py_XDECREF(pName);
|
206
|
-
PyDict_SetItemString(pDict->pObject,STR2CSTR(name_string),rtop_obj(args,0));
|
207
|
-
return Qtrue;
|
208
|
-
}
|
209
|
-
|
210
|
-
//:nodoc:
|
211
|
-
VALUE rp_inst_delegate(VALUE self,VALUE args)
|
212
|
-
{
|
213
|
-
VALUE name,name_string,rClassDict,result,rInstDict;
|
214
|
-
VALUE ret;
|
215
|
-
char *cname;
|
216
|
-
PObj *pClassDict,*pInstDict;
|
217
|
-
PyObject *pCalled;
|
218
|
-
|
219
|
-
if(rp_equal(args))
|
220
|
-
{
|
221
|
-
return rp_inst_attr_set(self,args);
|
222
|
-
}
|
223
|
-
if(!rp_has_attr(self,rb_ary_entry(args,0)))
|
224
|
-
{
|
225
|
-
int argc;
|
143
|
+
rName = ptorString(pName);
|
226
144
|
|
227
|
-
|
228
|
-
argc=RARRAY_LEN(args);
|
229
|
-
argv=ALLOC_N(VALUE,argc);
|
230
|
-
MEMCPY(argv,RARRAY_PTR(args),VALUE,argc);
|
231
|
-
return rb_call_super(argc,argv);
|
232
|
-
}
|
233
|
-
name=rb_ary_shift(args);
|
234
|
-
name_string=rb_funcall(name,rb_intern("to_s"),0);
|
235
|
-
cname=STR2CSTR(name_string);
|
145
|
+
Py_XDECREF(pName);
|
236
146
|
|
237
|
-
|
238
|
-
rInstDict=rb_iv_get(self,"@pinstdict");
|
239
|
-
Data_Get_Struct(rClassDict,PObj,pClassDict);
|
240
|
-
Data_Get_Struct(rInstDict,PObj,pInstDict);
|
241
|
-
pCalled=PyDict_GetItemString(pInstDict->pObject,cname);
|
242
|
-
if(!pCalled)
|
243
|
-
{
|
244
|
-
pCalled=PyDict_GetItemString(pClassDict->pObject,cname);
|
245
|
-
}
|
246
|
-
Py_XINCREF(pCalled);
|
247
|
-
result=ptor_obj_no_destruct(pCalled);
|
248
|
-
if(rb_obj_is_instance_of(result,cRubyPyFunction))
|
249
|
-
{
|
250
|
-
Py_XINCREF(rp_obj_pobject(self));
|
251
|
-
rb_ary_unshift(args,self);
|
252
|
-
ret=rp_call_func(pCalled,args);
|
253
|
-
return ret;
|
147
|
+
return rName;
|
254
148
|
}
|
255
|
-
return result;
|
256
149
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
VALUE rp_cla_from_class(PyObject *pClass)
|
261
|
-
{
|
262
|
-
PObj* self;
|
263
|
-
VALUE rClass=rb_class_new_instance(0,NULL,cRubyPyClass);
|
264
|
-
PyObject *pClassDict;
|
265
|
-
VALUE rDict;
|
266
|
-
Data_Get_Struct(rClass,PObj,self);
|
267
|
-
self->pObject=pClass;
|
268
|
-
pClassDict=PyObject_GetAttrString(pClass,"__dict__");
|
269
|
-
Py_XINCREF(pClassDict);
|
270
|
-
rDict=rp_obj_from_pyobject(pClassDict);
|
271
|
-
rb_iv_set(rClass,"@pdict",rDict);
|
272
|
-
return rClass;
|
273
|
-
}
|
274
|
-
|
275
|
-
VALUE rp_func_from_function(PyObject *pFunc)
|
276
|
-
{
|
277
|
-
PObj* self;
|
278
|
-
VALUE rFunc=rb_class_new_instance(0,NULL,cRubyPyFunction);
|
279
|
-
Data_Get_Struct(rFunc,PObj,self);
|
280
|
-
self->pObject=pFunc;
|
281
|
-
return rFunc;
|
282
|
-
}
|
283
|
-
|
284
|
-
VALUE rp_obj_wrap(PyObject* pObj)
|
285
|
-
{
|
286
|
-
VALUE rObj;
|
287
|
-
if(PyFunction_Check(pObj)||PyMethod_Check(pObj)||!PyObject_HasAttrString(pObj,"__dict__"))
|
288
|
-
{
|
289
|
-
return rp_func_from_function(pObj);
|
150
|
+
return rb_str_new2("__FREED__");
|
290
151
|
|
291
|
-
}
|
292
|
-
if(PyInstance_Check(pObj))
|
293
|
-
{
|
294
|
-
rObj=rp_inst_from_instance(pObj);
|
295
|
-
return rObj;
|
296
|
-
}
|
297
|
-
return rp_cla_from_class(pObj);
|
298
152
|
}
|
299
153
|
|
300
|
-
|
154
|
+
//Test to see the RubyPyObj has the supplied symbol as an attribute
|
155
|
+
int rpHasSymbol(VALUE self, VALUE symbol)
|
301
156
|
{
|
302
157
|
PObj *cself;
|
303
|
-
|
304
|
-
PyObject *pModule,*pFunc;
|
305
|
-
VALUE rReturn;
|
158
|
+
VALUE rName;
|
306
159
|
|
307
|
-
|
308
|
-
|
309
|
-
rReturn=rp_call_func(pFunc,args);
|
310
|
-
Py_XDECREF(pFunc);
|
160
|
+
Data_Get_Struct(self, PObj, cself);
|
161
|
+
rName = rb_funcall(symbol, rb_intern("to_s"), 0);
|
311
162
|
|
312
|
-
return
|
163
|
+
if(PyObject_HasAttrString(cself->pObject, STR2CSTR(rName))) return 1;
|
313
164
|
|
314
|
-
}
|
315
|
-
|
316
|
-
|
317
|
-
int rp_has_attr(VALUE self,VALUE func_name)
|
318
|
-
{
|
319
|
-
|
320
|
-
PObj *cself;
|
321
|
-
VALUE rName;
|
322
|
-
Data_Get_Struct(self,PObj,cself);
|
323
|
-
rName=rb_funcall(func_name,rb_intern("to_s"),0);
|
324
|
-
if(PyObject_HasAttrString(cself->pObject,STR2CSTR(rName))) return 1;
|
325
165
|
return 0;
|
326
166
|
}
|
327
167
|
|
328
|
-
|
329
|
-
VALUE
|
168
|
+
/* Tests whether the wrapped object will respond to the given method*/
|
169
|
+
VALUE rpRespondsTo(VALUE self, VALUE mname)
|
330
170
|
{
|
331
|
-
|
332
|
-
Data_Get_Struct(self,PObj,cself);
|
333
|
-
cself->pObject=rp_get_module(mname);
|
334
|
-
VALUE rDict;
|
335
|
-
PyObject *pModuleDict;
|
336
|
-
pModuleDict=PyModule_GetDict(cself->pObject);
|
337
|
-
Py_XINCREF(pModuleDict);
|
338
|
-
rDict=rp_obj_from_pyobject(pModuleDict);
|
339
|
-
rb_iv_set(self,"@pdict",rDict);
|
340
|
-
return self;
|
341
|
-
}
|
342
|
-
|
343
|
-
//Not completely accurate
|
344
|
-
int rp_is_func(VALUE pObj)
|
345
|
-
{
|
346
|
-
PObj* self;
|
347
|
-
Data_Get_Struct(pObj,PObj,self);
|
348
|
-
Py_XINCREF(self->pObject);
|
349
|
-
return (PyFunction_Check(self->pObject)||PyMethod_Check(self->pObject));
|
350
|
-
}
|
351
|
-
|
352
|
-
VALUE rp_cla_new_inst(VALUE self,VALUE args)
|
353
|
-
{
|
354
|
-
PyObject *pSelf;
|
355
|
-
pSelf=rp_obj_pobject(self);
|
356
|
-
return rp_call_func(pSelf,args);
|
357
|
-
}
|
358
|
-
|
359
|
-
VALUE rp_obj_responds(VALUE self,VALUE mname)
|
360
|
-
{
|
361
|
-
if(rp_has_attr(self,mname))
|
171
|
+
if(rpHasSymbol(self, mname))
|
362
172
|
{
|
363
173
|
return Qtrue;
|
364
174
|
}
|
365
|
-
return Qfalse;
|
366
|
-
}
|
367
|
-
|
368
|
-
int rp_equal(VALUE args)
|
369
|
-
{
|
370
|
-
VALUE mname=rb_ary_entry(args,0);
|
371
|
-
VALUE name_string=rb_funcall(mname,rb_intern("to_s"),0);
|
372
|
-
return Qtrue==rb_funcall(name_string,rb_intern("end_with?"),1,rb_str_new2("="));
|
373
|
-
}
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
int rp_double_bang(VALUE args)
|
378
|
-
{
|
379
|
-
VALUE mname=rb_ary_entry(args,0);
|
380
|
-
VALUE name_string=rb_funcall(mname,rb_intern("to_s"),0);
|
381
|
-
return Qtrue==rb_funcall(name_string,rb_intern("end_with?"),1,rb_str_new2("!!"));
|
382
|
-
}
|
383
|
-
|
384
|
-
VALUE rp_mod_attr_set(VALUE self,VALUE args)
|
385
|
-
{
|
386
|
-
VALUE rDict;
|
387
|
-
PObj *pDict;
|
388
|
-
VALUE mname=rb_ary_shift(args);
|
389
|
-
VALUE name_string=rb_funcall(mname,rb_intern("to_s"),0);
|
390
|
-
rb_funcall(name_string,rb_intern("chop!"),0);
|
391
|
-
if(!rp_has_attr(self,name_string))
|
392
|
-
{
|
393
|
-
int argc;
|
394
|
-
|
395
|
-
VALUE *argv;
|
396
|
-
argc=RARRAY_LEN(args);
|
397
|
-
argv=ALLOC_N(VALUE,argc);
|
398
|
-
MEMCPY(argv,RARRAY_PTR(args),VALUE,argc);
|
399
|
-
return rb_call_super(argc,argv);
|
400
|
-
}
|
401
|
-
if(NUM2INT(rb_funcall(args,rb_intern("size"),0))==1)
|
402
|
-
{
|
403
|
-
args=rb_ary_entry(args,0);
|
404
|
-
}
|
405
|
-
rDict=rb_iv_get(self,"@pdict");
|
406
|
-
Data_Get_Struct(rDict,PObj,pDict);
|
407
|
-
PyDict_SetItemString(pDict->pObject,STR2CSTR(name_string),rtop_obj(args,0));
|
408
|
-
return Qtrue;
|
409
|
-
}
|
410
|
-
|
411
|
-
//:nodoc:
|
412
|
-
VALUE rp_mod_delegate(VALUE self,VALUE args)
|
413
|
-
{
|
414
|
-
VALUE name,name_string,rDict,result;
|
415
|
-
VALUE ret;
|
416
|
-
PObj *pDict;
|
417
|
-
PyObject *pCalled;
|
418
|
-
if(rp_equal(args))
|
419
|
-
{
|
420
|
-
return rp_mod_attr_set(self,args);
|
421
|
-
}
|
422
|
-
// if(rp_double_bang)
|
423
|
-
// {
|
424
|
-
// return rp_mod_attr_db(args);
|
425
|
-
// }
|
426
|
-
if(!rp_has_attr(self,rb_ary_entry(args,0)))
|
427
|
-
{
|
428
|
-
int argc;
|
429
|
-
|
430
|
-
VALUE *argv;
|
431
|
-
argc=RARRAY_LEN(args);
|
432
|
-
argv=ALLOC_N(VALUE,argc);
|
433
|
-
MEMCPY(argv,RARRAY_PTR(args),VALUE,argc);
|
434
|
-
return rb_call_super(argc,argv);
|
435
|
-
}
|
436
|
-
name=rb_ary_shift(args);
|
437
|
-
name_string=rb_funcall(name,rb_intern("to_s"),0);
|
438
|
-
|
439
|
-
rDict=rb_iv_get(self,"@pdict");
|
440
|
-
Data_Get_Struct(rDict,PObj,pDict);
|
441
|
-
pCalled=PyDict_GetItemString(pDict->pObject,STR2CSTR(name_string));
|
442
|
-
Py_XINCREF(pCalled);
|
443
|
-
result=ptor_obj_no_destruct(pCalled);
|
444
|
-
if(rb_obj_is_instance_of(result,cRubyPyFunction))
|
445
|
-
{
|
446
|
-
ret=rp_call_func(pCalled,args);
|
447
|
-
return ret;
|
448
|
-
}
|
449
|
-
else if(rb_obj_is_instance_of(result,cRubyPyClass)&&(rb_funcall(args,rb_intern("empty?"),0)==Qfalse)&&PyCallable_Check(pCalled))
|
450
|
-
{
|
451
|
-
ret=rp_call_func(pCalled,args);
|
452
|
-
return ret;
|
453
|
-
}
|
454
|
-
return result;
|
455
175
|
|
456
|
-
|
457
|
-
|
458
|
-
// :nodoc:
|
459
|
-
inline void Init_BlankObject()
|
460
|
-
{
|
461
|
-
cBlankObject=rb_define_class_under(mRubyPythonBridge,"BlankObject",rb_cObject);
|
462
|
-
blank_obj_prep(cBlankObject);
|
176
|
+
return Qfalse;
|
463
177
|
}
|
464
178
|
|
465
179
|
/*
|
@@ -471,58 +185,10 @@ classes which wrap Python objects of similar names.
|
|
471
185
|
*/
|
472
186
|
inline void Init_RubyPyObject()
|
473
187
|
{
|
474
|
-
cRubyPyObject=rb_define_class_under(mRubyPythonBridge,"RubyPyObject",cBlankObject);
|
475
|
-
rb_define_alloc_func(cRubyPyObject,
|
476
|
-
rb_define_method(cRubyPyObject,"free_pobj",
|
477
|
-
rb_define_method(cRubyPyObject,"__name",
|
478
|
-
rb_define_method(cRubyPyObject,"respond_to?",
|
188
|
+
cRubyPyObject = rb_define_class_under(mRubyPythonBridge,"RubyPyObject", cBlankObject);
|
189
|
+
rb_define_alloc_func(cRubyPyObject, rpObjectAlloc);
|
190
|
+
rb_define_method(cRubyPyObject,"free_pobj", rpObjectFreePobj, 0);
|
191
|
+
rb_define_method(cRubyPyObject,"__name", rpObjectectGetName, 0);
|
192
|
+
rb_define_method(cRubyPyObject,"respond_to?", rpRespondsTo, 1);
|
479
193
|
|
480
|
-
}
|
481
|
-
|
482
|
-
|
483
|
-
/*
|
484
|
-
A wrapper class for Python Modules.
|
485
|
-
|
486
|
-
Methods calls are delegated to the equivalent Python methods/functions. Attribute references
|
487
|
-
return either the equivalent attribute converted to a native Ruby type, or wrapped reference
|
488
|
-
to a Python object. RubyPyModule instances should be created through the use of RubyPython.import.
|
489
|
-
|
490
|
-
*/
|
491
|
-
void Init_RubyPyModule()
|
492
|
-
{
|
493
|
-
cRubyPyModule=rb_define_class_under(mRubyPythonBridge,"RubyPyModule",cRubyPyObject);
|
494
|
-
rb_define_method(cRubyPyModule,"initialize",rp_mod_init,1);
|
495
|
-
rb_define_method(cRubyPyModule,"method_missing",rp_mod_delegate,-2);
|
496
|
-
}
|
497
|
-
|
498
|
-
/*
|
499
|
-
A wrapper class for Python classes and instances.
|
500
|
-
|
501
|
-
This allows objects which cannot easily be converted to native Ruby types to still be accessible
|
502
|
-
from within ruby. Most users need not concern themselves with anything about this class except
|
503
|
-
its existence.
|
504
|
-
|
505
|
-
*/
|
506
|
-
void Init_RubyPyClass()
|
507
|
-
{
|
508
|
-
cRubyPyClass=rb_define_class_under(mRubyPythonBridge,"RubyPyClass",cRubyPyObject);
|
509
|
-
rb_define_method(cRubyPyClass,"method_missing",rp_mod_delegate,-2);
|
510
|
-
rb_define_method(cRubyPyClass,"new",rp_cla_new_inst,-2);
|
511
|
-
}
|
512
|
-
|
513
|
-
//
|
514
|
-
// A wrapper class for Python functions and methods.
|
515
|
-
//
|
516
|
-
// This is used internally to aid RubyPyClass in delegating method calls.
|
517
|
-
//
|
518
|
-
|
519
|
-
void Init_RubyPyFunction()
|
520
|
-
{
|
521
|
-
cRubyPyFunction=rb_define_class_under(mRubyPythonBridge,"RubyPyFunction",cRubyPyObject);
|
522
|
-
}
|
523
|
-
|
524
|
-
void Init_RubyPyInstance()
|
525
|
-
{
|
526
|
-
cRubyPyInstance=rb_define_class_under(mRubyPythonBridge,"RubyPyInstance",cRubyPyObject);
|
527
|
-
rb_define_method(cRubyPyInstance,"method_missing",rp_inst_delegate,-2);
|
528
|
-
}
|
194
|
+
}
|