Skip to content

Commit c8da41d

Browse files
authored
Merge pull request #36 from jdlangs/pyobj_constructor
Allow generated type conversion using PyObject constructor
2 parents f601da6 + 97cfe53 commit c8da41d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/gentypes.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using Compat
44
import Compat: String, Symbol
5+
using PyCall
56

67
export @rosimport, rostypegen, rostypereset
78

@@ -633,6 +634,11 @@ function _get_rospy_class(typ::DataType)
633634
rospycls
634635
end
635636

637+
#Overwrite PyCall's default constructor to call the `convert` functions generated here
638+
PyCall.PyObject(m::AbstractMsg) = convert(PyCall.PyObject, m)
639+
PyCall.PyObject(s::AbstractSrv) = convert(PyCall.PyObject, s)
640+
PyCall.PyObject(s::AbstractService) = convert(PyCall.PyObject, s)
641+
636642
_jl_safe_name(name::AbstractString, suffix) = _nameconflicts(name) ?
637643
string(name,suffix) :
638644
name

test/typegeneration.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ pypose = convert(PyObject, posestamp)
4848
@test pypose[:pose][:position][:x] == 1.
4949
@test pypose[:pose][:position][:y] == 2.
5050
@test pypose[:pose][:position][:z] == 3.
51+
pypose2 = PyObject(posestamp)
52+
@test pypose2[:pose][:position][:x] == 1.
53+
@test pypose2[:pose][:position][:y] == 2.
54+
@test pypose2[:pose][:position][:z] == 3.
5155
pose2 = convert(geometry_msgs.msg.PoseStamped, pypose)
5256
@test pose2.pose.position.x == 1.
5357
@test pose2.pose.position.y == 2.

0 commit comments

Comments
 (0)