Python Properties & Swig

后端 未结 6 885
日久生厌
日久生厌 2021-01-30 09:24

I am attempting to create python bindings for some C++ code using swig. I seem have run into a problem trying to create python properties from some accessor functions I have for

6条回答
  •  醉梦人生
    2021-01-30 10:01

    Use Attributes.i

    In the SWIG Lib folder is a file called "attributes.i" which is not discussed in the documentation but that contains inline documentation.

    All you have to do is add the following line to your interface file.

    %include 
    

    You then receive a number of macros (such as %attribute) for defining attributes from existing methods.

    An excerpt from the documentation in the attributes.i file:

    The following macros convert a pair of set/get methods into a "native" attribute. Use %attribute when you have a pair of get/set methods to a primitive type like in:

      %attribute(A, int, a, get_a, set_a);
    
      struct A
      {
        int get_a() const;
        void set_a(int aa);
      };
    

提交回复
热议问题