Python bindings - interfaces


// C++ code
namespace ns
{
    $interface+ Ix : IObject
    {
        int32 Getx() const;
        void Setx(int32 x);
    };

    $struct+ X isa Ix
    {
        X() : m_x(0) {}

        int32 Getx() const { return m_x; }
        void Setx(int32 x) { m_x = x; }

        int32 m_x;
    };

    $function+ X CreateX() { return X(); }
}

Interfaces can be wrapped in python objects, providing support for calling all the interface methods directly from Python. For example:


# python code
x = ns.CreateX()
x.Ix.Setx(10)
print 'x.Ix.Getx() = ' + `x.Ix.Getx()`

produces the following output:

dir(x.Ix) = ['Getx', 'Setx']
x.Ix.Getx() = 10