pycall 0.1.0.alpha.20170226 → 0.1.0.alpha.20170302
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -3
- data/lib/pycall/libpython.rb +4 -2
- data/lib/pycall/pyobject.rb +15 -0
- data/lib/pycall/utils.rb +13 -0
- data/lib/pycall/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8c5abd1327e908691a79a42fdc536826e48d208
|
4
|
+
data.tar.gz: 4dd793ea028f6b9e47c9e74266d043de5751a74a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a75c2f1a5df62a881f8eee78fc72f5896bbc30d912610afc4f7b6bc719b43015cdddd03f87b6202a5ab782c4a182fd6fef181923e270cd1299bc9b738ff2709
|
7
|
+
data.tar.gz: 6fa5f34b243181d4340c3c265eb3c68b430c971976ba8a2ee8649d77a3df5ce547afa69b86d9e253cca7eb801f06e78647bc39ab2343198ebfb667f5e78f1a23
|
data/.travis.yml
CHANGED
data/lib/pycall/libpython.rb
CHANGED
@@ -152,6 +152,7 @@ module PyCall
|
|
152
152
|
attach_function :PyObject_Repr, [PyObject.by_ref], PyObject.by_ref
|
153
153
|
attach_function :PyObject_Str, [PyObject.by_ref], PyObject.by_ref
|
154
154
|
attach_function :PyObject_Type, [PyObject.by_ref], PyTypeObject.by_ref
|
155
|
+
attach_function :PyCallable_Check, [PyObject.by_ref], :int
|
155
156
|
|
156
157
|
# Bool
|
157
158
|
|
@@ -203,9 +204,9 @@ module PyCall
|
|
203
204
|
when libpython.find_symbol('PyUnicode_DecodeUTF8')
|
204
205
|
attach_function :PyUnicode_DecodeUTF8, [:string, :ssize_t, :string], PyObject.by_ref
|
205
206
|
when libpython.find_symbol('PyUnicodeUCS4_DecodeUTF8')
|
206
|
-
attach_function :PyUnicodeUCS4_DecodeUTF8, [:string, :ssize_t, :string], PyObject.by_ref
|
207
|
+
attach_function :PyUnicode_DecodeUTF8, :PyUnicodeUCS4_DecodeUTF8, [:string, :ssize_t, :string], PyObject.by_ref
|
207
208
|
when libpython.find_symbol('PyUnicodeUCS2_DecodeUTF8')
|
208
|
-
attach_function :PyUnicodeUCS2_DecodeUTF8, [:string, :ssize_t, :string], PyObject.by_ref
|
209
|
+
attach_function :PyUnicode_DecodeUTF8, :PyUnicodeUCS2_DecodeUTF8, [:string, :ssize_t, :string], PyObject.by_ref
|
209
210
|
end
|
210
211
|
|
211
212
|
# PyUnicode_AsUTF8String
|
@@ -279,6 +280,7 @@ module PyCall
|
|
279
280
|
attach_function :PyNumber_Subtract, [PyObject.by_ref, PyObject.by_ref], PyObject.by_ref
|
280
281
|
attach_function :PyNumber_Multiply, [PyObject.by_ref, PyObject.by_ref], PyObject.by_ref
|
281
282
|
attach_function :PyNumber_TrueDivide, [PyObject.by_ref, PyObject.by_ref], PyObject.by_ref
|
283
|
+
attach_function :PyNumber_Power, [PyObject.by_ref, PyObject.by_ref, PyObject.by_ref], PyObject.by_ref
|
282
284
|
|
283
285
|
# Compiler
|
284
286
|
|
data/lib/pycall/pyobject.rb
CHANGED
@@ -78,29 +78,40 @@ module PyCall
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def +(other)
|
81
|
+
other = Conversions.from_ruby(other)
|
81
82
|
value = LibPython.PyNumber_Add(self, other)
|
82
83
|
return value.to_ruby unless value.null?
|
83
84
|
raise PyError.fetch
|
84
85
|
end
|
85
86
|
|
86
87
|
def -(other)
|
88
|
+
other = Conversions.from_ruby(other)
|
87
89
|
value = LibPython.PyNumber_Subtract(self, other)
|
88
90
|
return value.to_ruby unless value.null?
|
89
91
|
raise PyError.fetch
|
90
92
|
end
|
91
93
|
|
92
94
|
def *(other)
|
95
|
+
other = Conversions.from_ruby(other)
|
93
96
|
value = LibPython.PyNumber_Multiply(self, other)
|
94
97
|
return value.to_ruby unless value.null?
|
95
98
|
raise PyError.fetch
|
96
99
|
end
|
97
100
|
|
98
101
|
def /(other)
|
102
|
+
other = Conversions.from_ruby(other)
|
99
103
|
value = LibPython.PyNumber_TrueDivide(self, other)
|
100
104
|
return value.to_ruby unless value.null?
|
101
105
|
raise PyError.fetch
|
102
106
|
end
|
103
107
|
|
108
|
+
def **(other)
|
109
|
+
other = Conversions.from_ruby(other)
|
110
|
+
value = LibPython.PyNumber_Power(self, other, LibPython.Py_None)
|
111
|
+
return value.to_ruby unless value.null?
|
112
|
+
raise PyError.fetch
|
113
|
+
end
|
114
|
+
|
104
115
|
def coerce(other)
|
105
116
|
[Conversions.from_ruby(other), self]
|
106
117
|
end
|
@@ -135,6 +146,10 @@ module PyCall
|
|
135
146
|
end
|
136
147
|
|
137
148
|
alias inspect to_s
|
149
|
+
|
150
|
+
def type
|
151
|
+
LibPython.PyObject_Type(self)
|
152
|
+
end
|
138
153
|
end
|
139
154
|
|
140
155
|
class PyTypeObject < FFI::Struct
|
data/lib/pycall/utils.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
module PyCall
|
2
2
|
module Utils
|
3
|
+
def callable?(pyobj)
|
4
|
+
case pyobj
|
5
|
+
when PyObject
|
6
|
+
when PyTypeObject
|
7
|
+
pyobj = PyObject.new(pyobj.to_ptr)
|
8
|
+
when PyObjectWrapper
|
9
|
+
pyobj = pyobj.__pyobj__
|
10
|
+
else
|
11
|
+
raise TypeError, "the argument must be a PyObject"
|
12
|
+
end
|
13
|
+
1 == LibPython.PyCallable_Check(pyobj)
|
14
|
+
end
|
15
|
+
|
3
16
|
def dir(pyobj)
|
4
17
|
value = LibPython.PyObject_Dir(pyobj)
|
5
18
|
return value.to_ruby unless value.null?
|
data/lib/pycall/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pycall
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.alpha.
|
4
|
+
version: 0.1.0.alpha.20170302
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenta Murata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02
|
11
|
+
date: 2017-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|