Primitives added in GrLibrary
are defined as void function(GrCall)
.
void myPrimitive(GrCall call) {
}
A primitive fetches its parameters with get
functions from GrCall
, the index matches the order of the parameters.
void myPrimitive(GrCall call) {
call.getInt(0) + call.getInt(1);
}
Sams as get
functions, we returns values with set
functions from GrCall
.
We are to call those the same order as its output parameters.
void myPrimitive(GrCall call) {
call.setInt(12);
}
We can dynamically know the type of the parameters with getInType
and getOutType
.
Those parameters are in a mangled form (use grUnmangle
to obtain a GrType
).
void myPrimitive(GrCall call) {
call.getInType(0);
call.getOutType(0);
}
In case of error, we call raise
. It's recommanded to exit the primitive and to not do any operation after raise
.
void myPrimitive(GrCall call) {
if(call.isNull(0)) {
call.raise("Error");
return;
}
}