@@ -183,7 +183,7 @@ function addtype!(mod::ROSMsgModule, typ::String)
183183 end
184184 pymod, pyobj = _pyvars (_fullname (mod), typ)
185185
186- deptypes = pyobj[ : _slot_types]
186+ deptypes = pyobj. _slot_types
187187 _importdeps! (mod, deptypes)
188188
189189 push! (mod. members, typ)
@@ -199,15 +199,15 @@ function addtype!(mod::ROSSrvModule, typ::String)
199199 @debug (" Service type import: " , _fullname (mod), " ." , typ)
200200 pymod, pyobj = _pyvars (_fullname (mod), typ)
201201
202- if ! haskey (pyobj, " _request_class" )
202+ if ! PyCall . hasproperty (pyobj, " _request_class" )
203203 error (string (" Incorrect service name: " , typ))
204204 end
205205
206206 # Immediately import dependencies from the Request/Response classes
207207 # Repeats are OK
208- req_obj = pymod[ string (typ," Request" )]
209- resp_obj = pymod[ string (typ," Response" )]
210- deptypes = [req_obj[ : _slot_types] ; resp_obj[ : _slot_types] ]
208+ req_obj = getproperty ( pymod, string (typ," Request" ))
209+ resp_obj = getproperty ( pymod, string (typ," Response" ))
210+ deptypes = [req_obj. _slot_types; resp_obj. _slot_types]
211211 _importdeps! (mod, deptypes)
212212
213213 push! (mod. members, typ)
222222function _pyvars (modname:: String , typ:: String )
223223 pymod = _import_rospy_pkg (modname)
224224 pyobj =
225- try pymod[ typ]
225+ try getproperty ( pymod, typ)
226226 catch ex
227227 isa (ex, KeyError) || rethrow (ex)
228228 error (" Message type '$typ ' not found in ROS package '$modname ', " ,
@@ -269,7 +269,7 @@ function _import_rospy_pkg(package::String)
269269 _rospy_modules[package] = pyimport (package)
270270 catch ex
271271 show (ex)
272- error (" python import error: $(ex. val[ : args] [1 ]) " )
272+ error (" python import error: $(ex. val. args[1 ]) " )
273273 end
274274 end
275275 _rospy_modules[package]
@@ -324,7 +324,7 @@ function modulecode(mod::ROSModule, rosrootmod::Module)
324324 push! (modcode,
325325 quote
326326 using PyCall
327- import Base: convert, getindex
327+ import Base: convert, getproperty
328328 import RobotOS
329329 import RobotOS. Time
330330 import RobotOS. Duration
@@ -390,8 +390,8 @@ function buildtype(mod::ROSMsgModule, typename::String)
390390 global _rospy_objects
391391 fulltypestr = _rostypestr (mod, typename)
392392 pyobj = _rospy_objects[fulltypestr]
393- memnames = pyobj[ : __slots__]
394- memtypes = pyobj[ : _slot_types]
393+ memnames = pyobj. __slots__
394+ memtypes = pyobj. _slot_types
395395 members = collect (zip (memnames, memtypes))
396396
397397 typecode (fulltypestr, :AbstractMsg , members)
@@ -404,16 +404,16 @@ function buildtype(mod::ROSSrvModule, typename::String)
404404
405405 req_typestr = _rostypestr (mod, string (typename," Request" ))
406406 reqobj = _rospy_objects[req_typestr]
407- memnames = reqobj[ : __slots__]
408- memtypes = reqobj[ : _slot_types]
407+ memnames = reqobj. __slots__
408+ memtypes = reqobj. _slot_types
409409 reqmems = collect (zip (memnames, memtypes))
410410 pyreq = :(RobotOS. _rospy_objects[$ req_typestr])
411411 reqexprs = typecode (req_typestr, :AbstractSrv , reqmems)
412412
413413 resp_typestr = _rostypestr (mod, string (typename," Response" ))
414414 respobj = _rospy_objects[resp_typestr]
415- memnames = respobj[ : __slots__]
416- memtypes = respobj[ : _slot_types]
415+ memnames = respobj. __slots__
416+ memtypes = respobj. _slot_types
417417 respmems = collect (zip (memnames, memtypes))
418418 pyresp = :(RobotOS. _rospy_objects[$ resp_typestr])
419419 respexprs = typecode (resp_typestr, :AbstractSrv , respmems)
436436# (2) Default outer constructer with no arguments
437437# (3) convert(PyObject, ...)
438438# (4) convert(..., o::PyObject)
439- # (5) getindex for accessing member constants
439+ # (5) getproperty for accessing member constants
440440function typecode (rosname:: String , super:: Symbol , members:: Vector )
441441 tname = _splittypestr (rosname)[2 ]
442442 @debug (" Type: " , tname)
@@ -477,17 +477,27 @@ function typecode(rosname::String, super::Symbol, members::Vector)
477477 # (4) Convert from PyObject
478478 push! (exprs, :(
479479 function convert (jlt:: Type{$jlsym} , o:: PyObject )
480- if convert (String, o[ " _type" ] ) != _typerepr (jlt)
480+ if convert (String, o. " _type" ) != _typerepr (jlt)
481481 throw (InexactError (:convert , $ jlsym, o))
482482 end
483483 jl = $ jlsym ()
484484 # Generated code here
485485 jl
486486 end
487487 ))
488- # (5) Accessing member variables through getindex
488+ # (5) Accessing member variables through getproperty
489489 push! (exprs, :(
490- getindex (:: Type{$jlsym} , s:: Symbol ) = RobotOS. _rospy_objects[$ rosname][s]
490+ function getproperty (:: Type{$jlsym} , s:: Symbol )
491+ try getproperty (RobotOS. _rospy_objects[$ rosname], s)
492+ catch ex
493+ isa (ex, KeyError) || rethrow (ex)
494+ try getfield ($ jlsym, s)
495+ catch ex2
496+ startswith (ex2. msg, " type DataType has no field" ) || rethrow (ex2)
497+ error (" Message type '" * $ (" $jlsym " ) * " ' has no property '$s '." )
498+ end
499+ end
500+ end
491501 ))
492502
493503 # Now add the meat to the empty expressions above
@@ -534,25 +544,25 @@ function _addtypemember!(exprs, namestr, typestr)
534544 if arraylen >= 0
535545 memexpr = :($ namesym:: Array{$j_typ,1} )
536546 defexpr = :([$ j_def for i = 1 : $ arraylen])
537- jlconexpr = :(jl.$ namesym = convert (Array{$ j_typ,1 }, o[ $ namestr] ))
547+ jlconexpr = :(jl.$ namesym = convert (Array{$ j_typ,1 }, o. $ namestr))
538548
539549 # uint8[] is string in rospy and PyCall's conversion to bytearray is
540550 # rejected by ROS
541551 if j_typ == :UInt8
542- pyconexpr = :(py[ $ namestr] =
552+ pyconexpr = :(py. $ namestr =
543553 pycall (pybuiltin (" str" ), PyObject, PyObject (o.$ namesym))
544554 )
545555 elseif _isrostype (typestr)
546- pyconexpr = :(py[ $ namestr] =
556+ pyconexpr = :(py. $ namestr =
547557 convert (Array{PyObject,1 }, o.$ namesym))
548558 else
549- pyconexpr = :(py[ $ namestr] = o.$ namesym)
559+ pyconexpr = :(py. $ namestr = o.$ namesym)
550560 end
551561 else
552562 memexpr = :($ namesym:: $j_typ )
553563 defexpr = j_def
554- jlconexpr = :(jl.$ namesym = convert ($ j_typ, o[ $ namestr] ))
555- pyconexpr = :(py[ $ namestr] = convert (PyObject, o.$ namesym))
564+ jlconexpr = :(jl.$ namesym = convert ($ j_typ, o. $ namestr))
565+ pyconexpr = :(py. $ namestr = convert (PyObject, o.$ namesym))
556566 end
557567 push! (typeargs, memexpr)
558568 insert! (jlconargs, length (jlconargs), jlconexpr)
0 commit comments