@@ -39,24 +39,24 @@ const _rospy_imports = Dict{String,ROSPackage}()
3939const _rospy_objects = Dict {String,PyObject} ()
4040const _rospy_modules = Dict {String,PyObject} ()
4141
42- const _ros_builtin_types = Dict {String, Symbol } (
43- " bool" => : Bool ,
44- " int8" => : Int8 ,
45- " int16" => : Int16 ,
46- " int32" => : Int32 ,
47- " int64" => : Int64 ,
48- " uint8" => : UInt8 ,
49- " uint16" => : UInt16 ,
50- " uint32" => : UInt32 ,
51- " uint64" => : UInt64 ,
52- " float32" => : Float32 ,
53- " float64" => : Float64 ,
54- " string" => : String ,
55- " time" => : Time ,
56- " duration" => : Duration ,
42+ const _ros_builtin_types = Dict {String,DataType } (
43+ " bool" => Bool,
44+ " int8" => Int8,
45+ " int16" => Int16,
46+ " int32" => Int32,
47+ " int64" => Int64,
48+ " uint8" => UInt8,
49+ " uint16" => UInt16,
50+ " uint32" => UInt32,
51+ " uint64" => UInt64,
52+ " float32" => Float32,
53+ " float64" => Float64,
54+ " string" => String,
55+ " time" => Time,
56+ " duration" => Duration,
5757 # Deprecated by ROS but supported here
58- " char" => : UInt8 ,
59- " byte" => : Int8 ,
58+ " char" => UInt8,
59+ " byte" => Int8,
6060 )
6161
6262# Abstract supertypes of all generated types
@@ -143,18 +143,18 @@ function _rosimport(package::String, ismsg::Bool, names::String...)
143143end
144144
145145"""
146- rostypegen()
146+ rostypegen(rosrootmod::Module=Main )
147147
148- Initiate the Julia type generation process after importing some ROS types. Creates modules in `Main`
149- with the same behavior as imported ROS modules in python. Should only be called once, after all
150- `@rosimport` statements are done.
148+ Initiate the Julia type generation process after importing some ROS types. Creates modules in
149+ rootrosmod (default is `Main`) with the same behavior as imported ROS modules in python.
150+ Should only be called once, after all `@rosimport` statements are done.
151151"""
152- function rostypegen ()
152+ function rostypegen (rosrootmod :: Module = Main )
153153 global _rospy_imports
154154 pkgdeps = _collectdeps (_rospy_imports)
155155 pkglist = _order (pkgdeps)
156156 for pkg in pkglist
157- buildpackage (_rospy_imports[pkg])
157+ buildpackage (_rospy_imports[pkg], rosrootmod )
158158 end
159159end
160160
@@ -277,38 +277,38 @@ function _import_rospy_pkg(package::String)
277277end
278278
279279# The function that creates and fills the generated top-level modules
280- function buildpackage (pkg:: ROSPackage )
280+ function buildpackage (pkg:: ROSPackage , rosrootmod :: Module = Main )
281281 @debug (" Building package: " , _name (pkg))
282282
283283 # Create the top-level module for the package in Main
284284 pkgsym = Symbol (_name (pkg))
285- pkgcode = Expr (:toplevel , :(module ($ pkgsym) end ))
286- Main. eval (pkgcode)
287- pkgmod = Main. eval (pkgsym)
285+ pkgcode = :(module ($ pkgsym) end )
288286
289287 # Add msg and srv submodules if needed
290288 @debug_addindent
291289 if length (pkg. msg. members) > 0
292290 msgmod = :(module msg end )
293- msgcode = modulecode (pkg. msg)
291+ msgcode = modulecode (pkg. msg, rosrootmod )
294292 for expr in msgcode
295293 push! (msgmod. args[3 ]. args, expr)
296294 end
297- eval (pkgmod , msgmod)
295+ push! (pkgcode . args[ 3 ] . args , msgmod)
298296 end
299297 if length (pkg. srv. members) > 0
300298 srvmod = :(module srv end )
301- srvcode = modulecode (pkg. srv)
299+ srvcode = modulecode (pkg. srv, rosrootmod )
302300 for expr in srvcode
303301 push! (srvmod. args[3 ]. args, expr)
304302 end
305- eval (pkgmod , srvmod)
303+ push! (pkgcode . args[ 3 ] . args , srvmod)
306304 end
305+ pkgcode = Expr (:toplevel , pkgcode)
306+ rosrootmod. eval (pkgcode)
307307 @debug_subindent
308308end
309309
310310# Generate all code for a .msg or .srv module
311- function modulecode (mod:: ROSModule )
311+ function modulecode (mod:: ROSModule , rosrootmod :: Module = Main )
312312 @debug (" submodule: " , _fullname (mod))
313313 modcode = Expr[]
314314
@@ -325,7 +325,7 @@ function modulecode(mod::ROSModule)
325325 end
326326 )
327327 # Import statement specific to the module
328- append! (modcode, _importexprs (mod))
328+ append! (modcode, _importexprs (mod, rosrootmod ))
329329 # The exported names
330330 push! (modcode, _exportexpr (mod))
331331
@@ -340,20 +340,20 @@ function modulecode(mod::ROSModule)
340340end
341341
342342# The imports specific to each module, including dependant packages
343- function _importexprs (mod:: ROSMsgModule )
343+ function _importexprs (mod:: ROSMsgModule , rosrootmod :: Module = Main )
344344 imports = Expr[Expr (:import , :RobotOS , :AbstractMsg )]
345345 othermods = filter (d -> d != _name (mod), mod. deps)
346- append! (imports, [Expr (:using ,:Main ,Symbol (m),:msg ) for m in othermods])
346+ append! (imports, [Expr (:using ,Symbol (rosrootmod) ,Symbol (m),:msg ) for m in othermods])
347347 imports
348348end
349- function _importexprs (mod:: ROSSrvModule )
349+ function _importexprs (mod:: ROSSrvModule , rosrootmod :: Module = Main )
350350 imports = Expr[
351351 Expr (:import , :RobotOS , :AbstractSrv ),
352352 Expr (:import , :RobotOS , :AbstractService ),
353353 Expr (:import , :RobotOS , :_srv_reqtype ),
354354 Expr (:import , :RobotOS , :_srv_resptype ),
355355 ]
356- append! (imports, [Expr (:using ,:Main ,Symbol (m),:msg ) for m in mod. deps])
356+ append! (imports, [Expr (:using ,Symbol (rosrootmod) ,Symbol (m),:msg ) for m in mod. deps])
357357 imports
358358end
359359
@@ -519,7 +519,7 @@ function _addtypemember!(exprs, namestr, typestr)
519519 end
520520 j_typ = _ros_builtin_types[typestr]
521521 # Compute the default value now
522- j_def = @eval _typedefault ($ j_typ)
522+ j_def = _typedefault (j_typ)
523523 end
524524
525525 namesym = Symbol (namestr)
0 commit comments