Open KunalSaini opened 7 years ago
Hi, I am using ref, ref-struct & ref-array to emulate following c structure
ref
ref-struct
ref-array
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
int *data
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.
Hi, I am using
ref
,ref-struct
&ref-array
to emulate following c structureIn my javascript , i am trying to create a object, set values and then read them back. However unable to do that for
int *data
andint *size
What am i missing here.