ref-array[0] is most likely what you are looking for.

[0]: https://github.com/TooTallNate/ref-array


On Sun, Mar 2, 2014 at 11:45 PM, vikhyath reddy <[email protected]>wrote:

> Hi,
>
> I am sure you guys must have had this figured out already. I am running
> into a bit of trouble trying to access struct data.
>
> I have a simple C method that fills a struct array
>
> typedef struct teststruct {
>
>   int a;
>
> } test;
>
> void testfunc(test **s)
>
> {
>
>   s[0] = malloc(sizeof(test));
>
>   s[0]->a = 2;
>
>   printf("assigned %d\n", s[0]->a);
>
>   s[1] = malloc(sizeof(test));
>
>   s[1]->a = 3;
>
>   printf("assigned %d\n", s[1]->a);
>
> }
>
> And I try to use this method from nodejs-ffi
>
> var ref = require('ref');
>
> var ffi = require('ffi');
>
> var Struct = require('ref-struct');
>
> var teststruct = Struct({
>
>         'a': 'int'
>
>     });
>
> var testlib = ffi.Library("/Users/vik/work/ffi-node/test.so", {
>
>         'testfunc': ['void', [ref.refType(ref.refType(teststruct))] ]
>
>     });
>
> var ptr = ref.alloc(ref.refType(teststruct));
>
> testlib.testfunc(ptr);
>
> console.log(ptr.deref().deref().a); // prints 2 as expected, 0th index in
> the struct array
>
> Now how do I print 3 which is the 1st index in the struct array?
>
>
> Much appreciated all your help.
>
> Thanks,
>
> Vik.
>
> --
> --
> 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
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
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

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to