zhangyuang / node-ffi-rs

Implement ffi in Node.js by Rust and NAPI
MIT License
159 stars 6 forks source link

How to use with double pointers ie. void** ? #63

Closed akarnil closed 1 month ago

akarnil commented 1 month ago

It would be nice if more examples are provided by this project,

The sqlite example by node-ffi offered me enough insight on how to use that library quickly, it would be great if the node-ffi examples were to be rewritten for this library,

My usecase is exactly the same as the one in the example linked above.

I have an opaque type and it needs to be allocated as the init function of my library takes a to initialise the object. I am a bit unsure of how to create a type and dereference it.

If you could point me towards the right direction it would be greatly appreciated

zhangyuang commented 1 month ago

you can use createPointer repeated to create multiple pointer

akarnil commented 1 month ago

I see that now, Thank you

zhangyuang commented 1 month ago

For example, there is a c function that receives double pointer type int **.

https://github.com/zhangyuang/node-ffi-rs/blob/master/cpp/sum.cpp#L35

In ffi-rs, we will call the foreign function by https://github.com/zhangyuang/node-ffi-rs/blob/master/test.ts#L256