Interfacing With The New Functions

In order to write plugins for breve, you'll first need to familiarize yourself with a feature of steve which is generally hidden from users—the C-style function call.

C-style function calls in breve work just as they do in C: they take a number of arguments and may return a value. In breve, a C-style function call is used to access code which is built into the breve engine (as opposed to code written in steve). In fact, the built-in class hierarchy provided with breve uses C-style function calls extensively to interface with the breve engine.

From the user's perspective, all computation in breve happens within objects. So when we write a plugin, we'll also give it an object interface. Here's a simple example in which the plugin simply provides some data (like a float or an int) back to the caller.

Object : mySimplePluginObject {
        + to get-input-from-plugin:
                return getPluginInput().
}

By packaging this functionality inside an object, breve users look at it as they do any other object, without needing any information about how the plugin works underneath.

The more important reason to use objects, however, is so that the plugin can be used by more than one agent simultaneously. Imagine, for example, a plugin which simulates neural networks. It's easy to imagine that a breve simulation might want to use several of these neural networks at the same time. Because the neural networking code requires a "persistent state", we would need a way to store many distinct states simultaneously.

Inside our breve object, we'll hold a pointer to C-memory representing these distinct states. Whenever a neural network function is needed, we'll pass that pointer back to the plugin so that it can operate on the correct state. Here's an example:

Object : myNeuralNetwork {
        + variables:
                networkPointer (pointer).

        + to init:
                networkPointer = newNeuralNetwork().

        + to iterate:
                neuralNetworkIterate(networkPointer).

        + to get-output:
                return neuralNetworkOutput(networkPointer).

        + to set-input to value (double):
                neuralNetworkSet(networkPointer, value).
}