113
113
function _usepkg (package:: ASCIIString , ismsg:: Bool , names:: ASCIIString... )
114
114
global _rospy_imports
115
115
if ! haskey (_rospy_imports, package)
116
- @debug (" Creating new package: " ,package," ." , ismsg ? " msg" : " srv" )
116
+ @debug (" Creating new package: " ,package," ." , ismsg ? " msg" : " srv" )
117
117
_rospy_imports[package] = ROSPackage (package)
118
118
end
119
119
rospypkg = _rospy_imports[package]
339
339
function _exportexpr (mod:: ROSMsgModule )
340
340
exportexpr = Expr (:export )
341
341
for m in mod. members
342
- push! (exportexpr. args, _nameconflicts (m) ?
343
- symbol (string (m," Msg" )) :
344
- symbol (m))
342
+ push! (exportexpr. args, symbol (_jl_safe_name (m," Msg" )))
345
343
end
346
344
exportexpr
347
345
end
@@ -366,11 +364,6 @@ function buildtype(mod::ROSMsgModule, typename::ASCIIString)
366
364
memtypes = pyobj[:_slot_types ]
367
365
members = collect (zip (memnames, memtypes))
368
366
369
- # Some ROS message names conflict with Julia built-in types
370
- # Append 'Msg' to the type name to resolve
371
- if _nameconflicts (typename)
372
- fulltypestr = fulltypestr * " Msg"
373
- end
374
367
typecode (fulltypestr, :MsgT , members)
375
368
end
376
369
@@ -408,49 +401,55 @@ function buildtype(mod::ROSSrvModule, typename::ASCIIString)
408
401
end
409
402
410
403
# Create the core generated expressions for a native Julia message type that has
411
- # data fields and interchanges with a python counterpart:
404
+ # data fields and interchanges with a python counterpart:
412
405
# (1) the 'type ... end' block
413
406
# (2) Default outer constructer with no arguments
414
407
# (3) convert(PyObject, ...)
415
408
# (4) convert(..., o::PyObject)
416
409
function typecode (rosname:: ASCIIString , super:: Symbol , members:: Vector )
417
410
tname = _splittypestr (rosname)[2 ]
418
411
@debug (" Type: " , tname)
419
- tsym = symbol (tname)
412
+
413
+ # generated code should not conflict with julia built-ins
414
+ # some messages need renaming
415
+ suffix = if super == :MsgT ; " Msg"
416
+ elseif super == :SrvT ; " Srv"
417
+ else ; " ROS" end
418
+ jlsym = symbol (_jl_safe_name (tname,suffix))
420
419
421
420
exprs = Expr[]
422
421
# First the empty expressions
423
422
# (1) Type declaration
424
423
push! (exprs, :(
425
- type $ tsym <: $super
424
+ type $ jlsym <: $super
426
425
# Generated code here
427
426
end
428
427
))
429
428
# (2) Default constructor, but only if the type has members
430
429
if length (members) > 0
431
430
push! (exprs, :(
432
- function $tsym ()
433
- $ tsym () # Generated code inside parens here
431
+ function $jlsym ()
432
+ $ jlsym () # Generated code inside parens here
434
433
end
435
434
))
436
435
else
437
436
push! (exprs, :())
438
437
end
439
438
# (3) Convert to PyObject
440
439
push! (exprs, :(
441
- function convert (:: Type{PyObject} , o:: $tsym )
440
+ function convert (:: Type{PyObject} , o:: $jlsym )
442
441
py = pycall (RobotOS. _rospy_objects[$ rosname], PyObject)
443
442
# Generated code here
444
443
py
445
444
end
446
445
))
447
446
# (4) Convert from PyObject
448
447
push! (exprs, :(
449
- function convert (jlt:: Type{$tsym } , o:: PyObject )
448
+ function convert (jlt:: Type{$jlsym } , o:: PyObject )
450
449
if convert (ASCIIString, o[" _type" ]) != _typerepr (jlt)
451
450
throw (InexactError ())
452
451
end
453
- jl = $ tsym ()
452
+ jl = $ jlsym ()
454
453
# Generated code here
455
454
jl
456
455
end
@@ -462,7 +461,7 @@ function typecode(rosname::ASCIIString, super::Symbol, members::Vector)
462
461
_addtypemember! (exprs, namestr, typ)
463
462
@debug_subindent
464
463
end
465
- push! (exprs, :(_typerepr (:: Type{$tsym } ) = $ rosname))
464
+ push! (exprs, :(_typerepr (:: Type{$jlsym } ) = $ rosname))
466
465
exprs
467
466
end
468
467
@@ -611,6 +610,10 @@ function _get_rospy_class(typ::DataType)
611
610
rospycls
612
611
end
613
612
613
+ _jl_safe_name (name:: AbstractString , suffix) = _nameconflicts (name) ?
614
+ string (name,suffix) :
615
+ name
616
+
614
617
# Check if the type name conflicts with a Julia builtin. Currently this is only
615
618
# some of the messages from the std_msgs.msg package
616
619
_nameconflicts (typename:: ASCIIString ) = isdefined (Base, symbol (typename))
0 commit comments