I have this structure (from the Teem library):
struct NrrdEncoding {
// ...
int (*read)(FILE *file, void *data, size_t elementNum,
Nrrd *nrrd, struct NrrdIoState_t *nio);
int (*write)(FILE *file, const void *data, size_t elementNum,
const Nrrd *nrrd, struct NrrdIoState_t *nio);
};
By default, Swig wants read and write to be userdata, which makes sense if they’re to be opaque and re-assignable. However, I want to be able to call these more than I want to be able to re-assign them, and I don’t know how. (Ideally I’d like to be able to do both.)
You need to give the object
NrrdEncodingmember functions via SWIG (ie: C functions that you bind as members of the object) that themselves will call the function pointers. It would work something like this:In Lua, if you have an
NrrdEncodingobject, you can callreadon it like this:object:read(...).