Callbacks required to add a new frontend language

In order to provide a language frontend to breve, a set of callbacks must be defined.

  • findObject: locate a class by name.

    void *(*findObject)( void *inObjectTypeUserData, char *name );
    

    When breve encounters a class name that it does not recognize, it will use this function to attempt to lookup the object. The pointer that is returned will be placed in the pointer field of a brObject. This pointer will likely be used later to instantiate objects or locate instance methods by your instantiate or findMethod callbacks.

  • findMethod: locate a method for a class by name and argument count.

    void *(*findMethod)( void *inObjectUserData, const char *inName, unsigned char *inTypes, int inTypeCount );
    

    When breve needs to call a method in an object, it will be looked up using this callback. The inObjectUserData argument refers to the object in which the method can be found—it is the pointer returned by your findObject callback. The inName argument is the name of the method to look for.

    The inTypeCount argument gives the number of arguments that will be passed to the method, and the inTypes argument contains the argument types. The types are described in [link]

  • instantiate: create an instance of an object.

    brInstance *(*instantiate)( brEngine *inEngine, brObject *inObject, const brEval **inArguments, int inArgCount )
    

    breve calls this function to create a new instance of a class. The inObject argument specifes the object to be created and contains the user data found with findObject in the userData field.

    The function is expected to add the newly created instance to the breve engine by calling brEngineAddInstance. brEngineAddInstance returns a brInstance, which should in turn be returned by instantiate. brEngineAddInstance is called as follows:

    brInstance *brEngineAddInstance( brEngine *inEngine, brObject *inObject, void *inInstanceUserData );
    

    The constructor arguments inArguments and count inArgCount are currently unused.

  • callMethod: trigger a method call in the frontend language.

    int (*callMethod)(brInstance *instancePointer, brMethod *method, brEval **arguments, brEval *result);
    

    The breve engine will need to trigger method calls in the frontend language for a number of events such as iteration and collision handling. This callback is used to trigger such events.

    The callback is given the instance to be used, a brInstance instance structure (which contains a native language instance pointer in the "pointer" field); the method to be called, a brMethod structure (which contains a native language method pointer in the "pointer" field); an array of brEval argument pointers, and a pointer to an output brEval structure.

    The callback should trigger the method call method for the instance instancePointer. It expects that the arguments array contains the number of items specified by the brMethod structure's argumentCount field.

  • isSubclass: determine whether a class is a subclass of another.

    int (*isSubclass)(brObject *class1, brObject *class2);
    

    In order to correctly handle certain interactions like collisions, the breve engine needs to know whether one class is a subclass of another.

    This callback is given two breve object pointers, and must return 1 if class1 is a subclass of class2, and 0 otherwise.

  • destroyObject: release memory allocated by your findObject callback.

    void (*destoryObject)(void *objectData);
    

    If your findObject callback allocates memory, this callback should release that memory.

  • destroyInstance: release memory allocated by your instantiate callback.

    void (*destoryInstance)(void *instanceData);
    

    If your instantiate callback allocates memory, this callback should release that memory.

  • destroyMethod: release memory allocated by your findMethod callback.

    void (*destoryMethod)(void *methodData);
    

    If your findMetho callback allocates memory, this callback should release that memory.

  • destroyObjectType: release the memory associated with your brObjectType.

    void (*destroyData)(void *objectTypeData);
    

    If you have allocate memory to be placed in the data field of the brObjectType, this callback should release that memory.