@@ -707,17 +707,18 @@ def disable(openscad_obj:OScO) -> OScO:
707707# --include() makes those methods available AND executes all code in
708708# scad_file_path.scad, which may have side effects.
709709# Unless you have a specific need, call use().
710- def use (scad_file_path :str , use_not_include :bool = True ) -> bool :
710+ def use (scad_file_path :str , use_not_include :bool = True , dest_namespace_dict : Dict = None ) :
711711 '''
712712 Opens scad_file_path, parses it for all usable calls,
713713 and adds them to caller's namespace.
714714 '''
715715 # These functions in solidpython are used here and only here; don't pollute
716716 # the global namespace with them
717- from .solidpython import extract_callable_signatures
717+ from .solidpython import parse_scad_callables
718718 from .solidpython import new_openscad_class_str
719719 from .solidpython import calling_module
720720
721+ contents = None
721722 try :
722723 with open (scad_file_path ) as module :
723724 contents = module .read ()
@@ -728,15 +729,17 @@ def use(scad_file_path:str, use_not_include:bool=True) -> bool:
728729 # Once we have a list of all callables and arguments, dynamically
729730 # add OpenSCADObject subclasses for all callables to the calling module's
730731 # namespace.
731- symbols_dicts = extract_callable_signatures ( scad_file_path )
732+ symbols_dicts = parse_scad_callables ( contents )
732733
733734 for sd in symbols_dicts :
734735 class_str = new_openscad_class_str (sd ['name' ], sd ['args' ], sd ['kwargs' ],
735736 scad_file_path , use_not_include )
736737 # If this is called from 'include', we have to look deeper in the stack
737738 # to find the right module to add the new class to.
738- stack_depth = 2 if use_not_include else 3
739- exec (class_str , calling_module (stack_depth ).__dict__ )
739+ if dest_namespace_dict is None :
740+ stack_depth = 2 if use_not_include else 3
741+ dest_namespace_dict = calling_module (stack_depth ).__dict__
742+ exec (class_str , dest_namespace_dict )
740743
741744 return True
742745
0 commit comments