Using python's ctypes, it's possible to specify a pointer that takes a type:
class METADATA(Structure):
_fields_ = [("classes", c_int),
("names", POINTER(c_char_p))]
With JNR, it looks like this:
public static class Metadata extends Struct{
public Metadata(jnr.ffi.Runtime rt) {
super(rt);
}
public final Struct.Unsigned32 classes = new Struct.Unsigned32();
public final Struct.Pointer names = new Struct.Pointer();
}
However, is it possible to type the names field as a Pointer to a String?
I'm not familiar with python's ctypes but assuming the type of
namesis eitherchar*orchar**you could try to use one of the following approaches.For a shared library,
The struct can be defined as follows
For the above, the following code will print
42 My Names are Stack, Overflow.