What should I specify to pass a "char *" in Deno.dlopen?
For example, this is how you would use it in Python:
10 Replies
https://deno.land/manual@v1.36.0/runtime/ffi_api#supported-types
I looked here but couldn't find the appropriate type
Not familiar with native code
Deno
Foreign Function Interface | Manual | Deno
As of Deno 1.13 and later, the FFI (foreign function interface) API allows users
to call libraries written in native languages that support the C ABIs (C/C++,
Rust, Zig, V, etc.) using
Deno.dlopen
.buffer
should do
if it is from the JS side
pointer
if from Native side
check out denonomicon
https://denonomicon.deno.dev/types (tho the styles are broken atm)Using buffer gets a funny response.
[Object: null prototype] {}
So pointer is probably the correct answer.
Learn about the pointer.
Given pointer, it asks for Deno.PointerValue as its argument, so it tries to find a way to convert the string to Deno.PointerValue.
Thank you!
are you passing a char * to the native code?
or are you sending it from native code to JS?
I send it to a Go program compiled from Deno to dll.
ah
idk how it is done generally but I can provide an example of how I do it
I convert my text into a
Uint8Array
with a TextEncoder
and pass it as a buffer
type
the native code can parse the byte stream as a string or whatever
I also pass an additional Uint8Array
to which the native code writes the response and I parse it in the JS side after the FFI call
[Object: null prototype] {}
The console displays the above results
I thought there was a problem with the dll, but I suspect there is a problem with my code because I called it from Python and it successfully asked for a response
Sorry
[Object: null prototype] {}
I looked at it and decided it wasn't the right response, but when I correctly parsed the results, it worked.
I mistakenly thought that an empty object was being returned.
Thank you
😢
<:hooray_deno:1035517542200004688>
result: 'buffer'
doesn't do anything different from pointer
as parameter types, they are different
but as return types, they are the sameI see, I learn a lot!
Thank you so much😭
<:cookie_deno:1002977285734932480>