im new to Node.js and node in general. I would like to use the C libgphoto library in my project but I fail to create pointers to some structs in the C library which need to be passed to the library APIs.
From the examples on node-ffi github i created the following:
var ffi = require('../../')
var ref = require('ref');
var retval;
var GPCameraFile = ref.types.void; // CameraFile is LibGphoto struct
var CameraFilePtr = ref.refType(GPCameraFile);
var file = ref.alloc(CameraFilePtr);
var GPContext = ref.types.void; // GPContext is LibGphoto struct
var GPContextPtr = ref.refType(GPContext);
var Context = ref.alloc(GPContextPtr);
var GPCamera = ref.types.void; // GPCamera is LibGphoot struct I would need pointer to pass to lib APIs
var GPCameraPtr = ref.refType(GPCamera);
var Camera = ref.alloc(GPCameraPtr)
var libgphoto = ffi.Library('libgphoto2.dylib', {
'gp_camera_new': [ 'void', [ 'pointer' ] ],
'gp_context_new': [ 'pointer', [ ] ],
'gp_camera_capture_preview': [ 'int', [ 'pointer','pointer' ,'pointer' ] ],
'gp_file_new': [ 'int', [ CameraFilePtr ] ],
'gp_camera_init': [ 'int', [ 'pointer','pointer' ] ]
})
Context = libgphoto.gp_context_new.async(function (err, res) {
Camera = libgphoto.gp_camera_new.async(Context, function (err, res) {
retval = libgphoto.gp_file_new.async(file, function (err, res) {
console.log(retval)
retval = libgphoto.gp_camera_init.async(Camera, Context, function (err, res) {
console.log(retval)
//retval = libgphoto.gp_camera_capture_preview(Camera, file, context)
console.log(retval)
})
});
})
} )
That is running but the refTypes Context, Camera and file stay 'undefined'
In C usage of that call would look like this:
Camera *canon;
GPContext *canoncontext;
CameraFile *file;
canoncontext= sample_create_context();
gp_camera_new(&canon);
retval = gp_file_new(&file);
I would like to know how to setup this refs correctly so that I can pass them to the functions.
Many Thanks in Advance
Mumford