Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested structures with array #31

Open
KunalSaini opened this issue Jun 2, 2017 · 0 comments
Open

Nested structures with array #31

KunalSaini opened this issue Jun 2, 2017 · 0 comments

Comments

@KunalSaini
Copy link

Hi, I am using ref, ref-struct & ref-array to emulate following c structure

struct InnerStruct
{
  int *data;
  int *size;
  int allocatedSize;
  int numDimensions;
  unsigned char canFreeData;
};
typedef struct {
  emxArray_real_T *myProp;
} OuterStruct;

In my javascript , i am trying to create a object, set values and then read them back. However unable to do that for int *data and int *size

const ref = require('ref');
const StructTypeFactory = require('ref-struct');
const ArrayTypeFactory = require('ref-array');

const inttype = ref.types.int;
const booltype = ref.types.bool;
const IntArraytype = ArrayTypeFactory(inttype);

const innerStruct = StructTypeFactory({
  data: IntArraytype,
  size: IntArraytype,
  allocatedSize: inttype,
  numDimensions: inttype,
  canFreeData: booltype,
});

const outerStructure = StructTypeFactory();
outerStructure.defineProperty('myProp', ref.refType(innerStruct));

const instance = new outerStructure();
const myPropInst = new innerStruct({
  data: new IntArraytype([12, 34, 23, 45]),
  size: new IntArraytype([0, 4]),
  allocatedSize: 16,
  numDimensions: 1,
  canFreeData: true,
});

instance.myProp = myPropInst.ref();

console.dir(instance.myProp.deref().allocatedSize); //WORKS fine, return 16
console.dir(instance.myProp.deref().numDimensions); //WORKS fine, return 1
console.dir(instance.myProp.deref().canFreeData); //WORKS fine, return true
console.dir(instance.myProp.deref().data); //Does NOT give back the expected array [12, 34, 23, 45]
console.dir(instance.myProp.deref().size); //Does NOT give back the expected array [0, 4]

What am i missing here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant