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
pointerfield of abrObject. This pointer will likely be used later to instantiate objects or locate instance methods by yourinstantiateorfindMethodcallbacks. -
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
inObjectUserDataargument refers to the object in which the method can be found—it is the pointer returned by yourfindObjectcallback. TheinNameargument is the name of the method to look for.The
inTypeCountargument gives the number of arguments that will be passed to the method, and theinTypesargument 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
inObjectargument specifes the object to be created and contains the user data found withfindObjectin theuserDatafield.The function is expected to add the newly created instance to the breve engine by calling
brEngineAddInstance.brEngineAddInstancereturns abrInstance, which should in turn be returned byinstantiate.brEngineAddInstanceis called as follows:brInstance *brEngineAddInstance( brEngine *inEngine, brObject *inObject, void *inInstanceUserData );
The constructor arguments
inArgumentsand countinArgCountare 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
brInstanceinstance structure (which contains a native language instance pointer in the "pointer" field); the method to be called, abrMethodstructure (which contains a native language method pointer in the "pointer" field); an array ofbrEvalargument pointers, and a pointer to an outputbrEvalstructure.The callback should trigger the method call
methodfor the instanceinstancePointer. It expects that theargumentsarray contains the number of items specified by thebrMethodstructure'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
class1is a subclass ofclass2, and 0 otherwise. -
destroyObject:release memory allocated by yourfindObjectcallback.void (*destoryObject)(void *objectData);
If your
findObjectcallback allocates memory, this callback should release that memory. -
destroyInstance:release memory allocated by yourinstantiatecallback.void (*destoryInstance)(void *instanceData);
If your
instantiatecallback allocates memory, this callback should release that memory. -
destroyMethod:release memory allocated by yourfindMethodcallback.void (*destoryMethod)(void *methodData);
If your
findMethocallback allocates memory, this callback should release that memory. -
destroyObjectType:release the memory associated with yourbrObjectType.void (*destroyData)(void *objectTypeData);
If you have allocate memory to be placed in the
datafield of thebrObjectType, this callback should release that memory.
