diff --git a/swig/comedi.i b/swig/comedi.i index 515ed0c..478331b 100644 --- a/swig/comedi.i +++ b/swig/comedi.i @@ -44,11 +44,6 @@ //#define SWIGPYTHONONLYSHORT #ifdef SWIGPYTHON -#ifdef SWIGPYTHONONLYSHORT -%rename("%(strip:[COMEDI_])s", regextarget=1) "COMEDI_.*"; -%rename("%(strip:[comedi_])s", regextarget=1) "comedi_.*"; -#endif - // These need to be explicitly written as unsigned ints %rename(CR_FLAGS_MASK) _CR_FLAGS_MASK; %rename(CR_INVERT) _CR_INVERT; @@ -118,19 +113,24 @@ unsigned int NI_AO_SCAN_BEGIN_SRC_RTSI(unsigned int rtsi_channel); %array_class(lsampl_t, lsampl_array); %array_class(comedi_insn, insn_array); -#ifndef SWIGPYTHONONLYSHORT +#ifdef SWIGPYTHONONLYSHORT %insert("python") %{ -# Add entries in module dictionary to strip comedi_/COMEDI_ prefix -import copy + delete_comedi_prefix = True + %} +#else +%insert("python") %{ + delete_comedi_prefix = False + %} +#endif + +%insert("python") %{ +# Add entries in module dictionary without comedi_/COMEDI_ prefix import re -myglobals = copy.copy(globals()) -# Copy dictionary before -for k,v in myglobals.items(): +for k,v in globals().copy().items(): if re.match('^comedi_', k, flags=re.IGNORECASE): globals()[k[7:]] = v - # uncommenting following line removes compatibility with old code using - # comedi_ prefix: - # globals().pop(k) -del re, k, v + if delete_comedi_prefix: + globals().pop(k) # Break backwards compatibility +del re, k, v, delete_comedi_prefix %} -#endif +