You examples are a little confusing, but I believe you are needing to call .deref() in these cases.
Like here: `_f.t_p` that would be a pointer (a Buffer instance) to a "t" struct, so to turn that back into the "t" struct instance to you need to call `_f.t_p.deref()`. Then you can access `t_i` as expected. Let me know if that's what you needed! On Tue, Sep 4, 2012 at 10:09 PM, rhasson <[email protected]> wrote: > Nate, > > I'm back with some more questions about node-struct and handling nested > structures. > > In the example below, I created one simple struct with a single Int and > another struct with an Int and a pointer to the first struct. > What I noticed is that I can't access the int inside the nested structure. > Another thing I noticed is that if I do something like this: > var myStruct = Struct(); > myStruct.defineProperty('someProp', ref.refType('int')); > > var t = new myStruct(); > > accessing t.someProp fails. If I change the definition above to > ('someProp', ref.types.int), I can access t.someProp with no problem. > > Why is this and how to deal with this? > > Below you can see I'm running into the same issue, however since I'm > defining the property is a refType(struct_one) I can't figure out how to > access its propertied. It seems like it's an unrecognized type. > > I have this .js file: > > var ffi = require('ffi'); > var ref = require('ref'); > var Struct = require('ref-struct'); > > //define a simple struct > var t = Struct({ > 't_i': 'int' > }); > > //define a second stuct with a pointer to an instance of the first struct > var f = new Struct(); > f.defineProperty('fp_i', ref.types.int); > f.defineProperty('t_p', ref.refType(t)); > > var tPtr = ref.refType(t); > var fPtr = ref.refType(f); > > var lib = './libffi.so.1.0.1'; > > var l = ffi.Library(lib, { > 'setT': ['void', [fPtr]] > }); > > var _f = new f(); > var x = null, d = null; > console.log(_f); //I see the buffer that's created > l.setT(_f.ref()); > > console.log(_f); //I see the updated buffer > > console.log('fp_i: ', _f.fp_i); //works great, returns the expected value > > console.log('t_i: ', _f.t_p.t_i); //this is undefined, not sure how to > access the nested struct's members. > > My .c file looks like this: > > #include <stdio.h> > #include <string.h> > > typedef struct t { > int t_i; > } t; > > typedef struct f { > int fp_i; > struct t *t_p; > } f; > > void setT(f *i) { > t *tt; > > i->fp_i = 5; > tt->t_i = 6; > i->t_p = tt; > printf("\tThis is a test: %i\n", i->t_p->t_i); //successfully prints 6 > } > > void main(){} > > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
