swig: remove comedi_ prefix from the function names
python always use the namespace of the library so it was redundant. so what used to be written comedi.comedi_open() can be written comedi.open(). The main trick is to add a special python code that allows for the old names to still be compatible. That avoids to break every single python program previously written.
This commit is contained in:
parent
1465834a26
commit
371dcc56e6
1 changed files with 26 additions and 0 deletions
|
@ -38,6 +38,11 @@
|
||||||
%include "carrays.i"
|
%include "carrays.i"
|
||||||
%include "typemaps.i"
|
%include "typemaps.i"
|
||||||
|
|
||||||
|
#ifdef SWIGPYTHON
|
||||||
|
%rename("%(strip:[COMEDI_])s", regextarget=1) "COMEDI_.*";
|
||||||
|
%rename("%(strip:[comedi_])s", regextarget=1) "comedi_.*";
|
||||||
|
#endif
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
static unsigned int cr_pack(unsigned int chan, unsigned int rng, unsigned int aref){
|
static unsigned int cr_pack(unsigned int chan, unsigned int rng, unsigned int aref){
|
||||||
return CR_PACK(chan,rng,aref);
|
return CR_PACK(chan,rng,aref);
|
||||||
|
@ -69,3 +74,24 @@ static unsigned int cr_aref(unsigned int a){
|
||||||
%array_class(sampl_t, sampl_array);
|
%array_class(sampl_t, sampl_array);
|
||||||
%array_class(lsampl_t, lsampl_array);
|
%array_class(lsampl_t, lsampl_array);
|
||||||
%array_class(comedi_insn, insn_array);
|
%array_class(comedi_insn, insn_array);
|
||||||
|
|
||||||
|
%insert("python") %{
|
||||||
|
# Trick to allow accessing functions and constants with their original C name
|
||||||
|
import sys
|
||||||
|
|
||||||
|
class __Wrapper(object):
|
||||||
|
def __init__(self, wrapped):
|
||||||
|
self.wrapped = wrapped
|
||||||
|
|
||||||
|
def __getattr__(self, name):
|
||||||
|
try:
|
||||||
|
return getattr(self.wrapped, name)
|
||||||
|
except AttributeError:
|
||||||
|
if name.startswith("comedi_") or name.startswith("COMEDI_"):
|
||||||
|
return getattr(self.wrapped, name[7:])
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
|
sys.modules[__name__] = __Wrapper(sys.modules[__name__])
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue