Glad you're figuring it out on your own :p I don't get your latest question: you're already passing a struct in by reference in the setT() function so I'm not sure what's different.
On Wed, Sep 5, 2012 at 1:44 PM, rhasson <[email protected]> wrote: > Now, the issue I'm having is in trying to port this methodology to an > external library out of my control (libpst) which does not use malloc on > local structs that then have pointers assigned to the main struct that was > passed in by reference which are then overwritten. Is there a way to > address this using node-ref and node-struct ? > > > On Wednesday, September 5, 2012 1:09:48 AM UTC-4, rhasson 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
