1

I'm using node-ffi and I have a structure that needs to be passed. A few of the variables in the structure are arrays. How do I define this in the JavaScript wrapper?

C header:

typedef struct
{
    unsigned char myUChar;
    float fmyFloat;
    float arrayFloat[ARRAY_SIZE];
} sMyStruct;

JavaScript wrapper:

var ffi = require('ffi');
var Struct require('ref-struct');

var sMyStruct = Struct({
    'myUChar': 'uchar',
    'fmyFloat': 'float',
    'arrayFloat[ARRAY_SIZE]': 'float'  // Would this work??
});

Is there a tutorial which indicates all of the variables that can be passed into node-ffi anyone can point me to? (For example can I actually pass 'uchar'?)

1 Answer 1

3

Turns out the correct way to declare the array in a struct is actually now:

var Struct require('ref-struct');
var ArrayType require('ref-array');

var sMyStruct = Struct({
    'arrayFloat': ArrayType('float', 10) // array of floats, length 10
});

I still need to test this a bit more thoroughly, and as far as a list of types goes I found a decent one here: https://www.npmjs.com/package/node-ffi

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.