tjfontaine / node-ffi-generate

Generate ffi bindings from header files
131 stars 22 forks source link

Issue with arrays of structs inside other structs #2

Open wwwtyro opened 10 years ago

wwwtyro commented 10 years ago

Here's a reproducible example:

test.h:

typedef struct fooStruct_
{
    int bar;
} fooStruct;

typedef struct bazStruct_
{
    fooStruct  foos[2];
} bazStruct;

void someFunc(bazStruct* baz);

ffi-generate -f test.h -l foo > foo.js

foo.js:

var FFI = require('ffi'),
    ArrayType = require('ref-array'),
    Struct = require('ref-struct'),
    ref = require('ref');

var voidPtr = ref.refType(ref.types.void);

exports.CONSTANTS = {
};

var fooStruct_ = exports.fooStruct_ = ArrayType(fooStruct_, 2); // this seems broken to me
var fooStruct_Ptr = exports.fooStruct_Ptr = ref.refType(fooStruct_);
var bazStruct = exports.bazStruct = Struct({
  foos: fooStruct_,
});
var bazStructPtr = exports.bazStructPtr = ref.refType(bazStruct);

exports.foo = new FFI.Library('foo', {
  someFunc: [ref.types.void, [
    bazStructPtr,
  ]],
});

node foo.js:

assert.js:92
  throw new assert.AssertionError({
        ^
AssertionError: could not determine a proper "type" from: undefined
    at Object.coerceType (/home/rye/Downloads/OculusSDK/LibOVR/Src/node_modules/ref/lib/ref.js:389:3)
    at Array (/home/rye/Downloads/OculusSDK/LibOVR/Src/node_modules/ref-array/lib/array.js:20:19)
    at Object.<anonymous> (/home/rye/Downloads/OculusSDK/LibOVR/Src/foo.js:11:39)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3
coconitro commented 9 years ago

Running into this as well. I know this is an older ticket but OP did you ever find a work around?