Skip to content

Commit

Permalink
Allow generated type conversion using PyObject constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
jdlangs committed Sep 5, 2017
1 parent f601da6 commit 97cfe53
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/gentypes.jl
Expand Up @@ -2,6 +2,7 @@

using Compat
import Compat: String, Symbol
using PyCall

export @rosimport, rostypegen, rostypereset

Expand Down Expand Up @@ -633,6 +634,11 @@ function _get_rospy_class(typ::DataType)
rospycls
end

#Overwrite PyCall's default constructor to call the `convert` functions generated here
PyCall.PyObject(m::AbstractMsg) = convert(PyCall.PyObject, m)
PyCall.PyObject(s::AbstractSrv) = convert(PyCall.PyObject, s)
PyCall.PyObject(s::AbstractService) = convert(PyCall.PyObject, s)

_jl_safe_name(name::AbstractString, suffix) = _nameconflicts(name) ?
string(name,suffix) :
name
Expand Down
4 changes: 4 additions & 0 deletions test/typegeneration.jl
Expand Up @@ -48,6 +48,10 @@ pypose = convert(PyObject, posestamp)
@test pypose[:pose][:position][:x] == 1.
@test pypose[:pose][:position][:y] == 2.
@test pypose[:pose][:position][:z] == 3.
pypose2 = PyObject(posestamp)
@test pypose2[:pose][:position][:x] == 1.
@test pypose2[:pose][:position][:y] == 2.
@test pypose2[:pose][:position][:z] == 3.
pose2 = convert(geometry_msgs.msg.PoseStamped, pypose)
@test pose2.pose.position.x == 1.
@test pose2.pose.position.y == 2.
Expand Down

0 comments on commit 97cfe53

Please sign in to comment.