Game Development Reference
In-Depth Information
[ type type[ ] array
(arg-types) ret-type (method) return type
V void
For example, the Java method
long JavaMethod1(int number, String str, int[] intarray1);
has the following type signature:
(ILjava/lang/String;[I)J
Another example is the AddRotation() function from the Orientation class.
void AddRotation(float AngleIncrementDegrees)
The signature type for this function would be
(F)V
The F would represent the float input parameter, and the V would represent the void return type.
Calling Native Code from Java and Accessing Java Methods from
Native Code
To call a native function from Java code, you would use the native function name without the
mangled prefix with the extra identifying information. For example, to call the native function
AddRotationNative() shown in Listing 11-5, you would use the code shown in Listing 11-4.
Listing 11-4. Calling Native Code from Java
void AddRotationToObject(Orientation O, float AngleAmount)
{
AddRotationNative(O, AngleAmount);
}
The native function AddRotationNative() shown in Listing 11-5 calls the AddRotation() function for
the Orientation object that is passed into the function and held in the Orient variable.
The AddRotationNative() function does the following:
Gets the class of the Java object Orient by calling the GetObjectClass() JNI
function and assigns it to the OrientationClass variable
1.
Gets the method id of a specific function by calling the GetMethodID()
JNI function with parameters including the function name, which is
"AddRotation" ; the function signature type, which is "(F)V" ; and the Java
class object that contains the function, which is OrientationClass . This
method id is assigned to the MethodID variable.
2.
 
Search WWH ::




Custom Search