The Interface Files

The interface files are the heart of Pyste. The user creates one or more interface files declaring the classes and functions he wants to export, and then invokes Pyste passing the interface files to it. Pyste then generates a single cpp file with Boost.Python code, with all the classes and functions exported.

Besides declaring the classes and functions, the user has a number of other options, like renaming e excluding classes and member functionis. Those are explained later on.

Basics

Suppose we have a class and some functions that we want to expose to Python declared in the header hello.h:

    struct World
    {
        World(std::string msg): msg(msg) {} 
        void set(std::string msg) { this->msg = msg; }
        std::string greet() { return msg; }
        std::string msg;
    };

    enum choice { red, blue };
    
    namespace test {
    
    void show(choice c) { std::cout << "value: " << (int)c << std::endl; }
    
    }

We create a file named hello.pyste and create instances of the classes Function, Class and Enum:

    Function("test::show", "hello.h")
    Class("World", "hello.h")
    Enum("choice", "hello.h")

That will expose the class, the free function and the enum found in hello.h.

Inheritance

Pyste automatically generates the correct code (specifying bases<> in the class_ declaration) if the Class() function that exports the base classes and their children are in the same Pyste file. If that's not the case, you have to indicate that there's a relationship between the Pyste files using the Import function specifying the other Pyste file.

Suppose we have two classes, A and B, and A is a base class for B. We create two Pyste files:

A.pyste:

    Class("A", "A.h")

B.pyste:

    Import("A.pyste")
    Class("B", "B.h")

Note that we specify that B needs to know about A to be properly exported.