A foreign function interface (FFI) is a mechanism for one language to interact with software written in another language.
Questions tagged [ffi]
1778 questions
0
votes
1 answer
In Racket's FFI, how do you register a callback that takes a list?
I need to define a function in Racket's FFI that takes a callback:
(define-ffi-definer define-lib (ffi-lib "libLib"))
(define callback
(_fun [len : _int]
[elems : (_list i _int)] -> _void))
(define-lib registerCallback
(_fun callback ->…

Nate
- 12,499
- 5
- 45
- 60
0
votes
1 answer
Returning a dependent pair from a foreign function
I have the following Chez support file:
(define list-copy-with-length (xs)
(cons (length xs) (list-copy xs)))
and I have this Idris file:
%foreign "scheme,chez:list-copy-with-length"
prim__listToVect : List t -> (Nat, Vect n t)
listToVect : List…

shadowtalker
- 12,529
- 3
- 53
- 96
0
votes
0 answers
Create a safe binding between C and Rust for non opaque datatypes passed as *void
I need to interface with a third party C library where I have a function like this:
void setOption(const char* optionName, void* value) {
if (strcmp(optionName, "OPTION_1") == 0) {
gOption1 = (const uint_fast64_t) value;
} else…

Ivan
- 3
- 3
0
votes
1 answer
Pass 2D array of bytes to C in Rust
I've written a function in C with this signature:
write_stuff(char **pages, uint32 page_count);
pages will be an array of 128 elements, with each element either NULL or pointing to a char array of 8192 bytes. So, an array of arrays with fixed,…

ccleve
- 15,239
- 27
- 91
- 157
0
votes
1 answer
`The Flutter SDK is not available` when running `dart run ffigen`
I'm trying to run dart run ffigen but I'm getting this error
$ dart run ffigen
The Flutter SDK is not available.
#0 BoundSdkSource.getDirectory (package:pub/src/source/sdk.dart:125:7)
#1 SystemCache.load…

noibe
- 327
- 5
- 18
0
votes
0 answers
Request answers to questions found when calling Dll libraries using FFI-NAPI
I am confused。
When using FFI-NAPI - Dll 。
The return value does not receive anything。
But print out the content (stdut) at the terminal。
I will post part of the code below and keep trying. I guess it will work after using FF-callback, but I'm…

曾钰涵
- 11
- 2
0
votes
0 answers
Bindgen: How to include all functions in some files but only certain functions in other files?
I have two folders that I want to create bindings for:
Include: - I need everything in this folder
Src: - I only need 3 functions (of many) from one file (of many)
All of the required files are included in wrapper.h.
I can create bindings for the…

Jambalaya
- 31
- 4
0
votes
0 answers
Running 'npm install' on previously working Node.js project, now gives errors. (Possibly problem with 'ffi-napi' package or 'node-gyp' dependency)
I wrote a web app back in November 2020, and it was working perfectly fine then.
But now when I download it, and try to install it via 'npm install' I get a ton of errors.
The project is located here if anyone wants to try…

pintof
- 1
- 1
0
votes
1 answer
How to declare argc, argv in ruby ffi, and how to pass proper values to it?
Answered: What is proper ruby ffi code for this function:
void glutInit(int *argc, char ** argv);
attach_function :glutInit, [:pointer, :pointer], :void
Answered: How to handle array of C-strings?
Like a pointer!
Still unanswered:How to change…

przemo_li
- 3,932
- 4
- 35
- 60
0
votes
0 answers
Binding a C++ virtual class for use in Python
I want to know a way of consuming the VST3 SDK from Python. In its essence, the VST3 architecture mimics COM.
My end goal is using the GetPluginFactory exported by a VST3 plugin in Python. This function returns a pointer to a C++ virtual class. I am…

demberto
- 489
- 5
- 15
0
votes
0 answers
Load a ctypes dlopen handle with cffi
I have this weird case where I absolutely need to open a library using ctypes._dlopen (intercepted method that use a weird memory layout) and then so I can use it in a more simpler way (with my header definitions) I need to load the handle (so the…

hube
- 1
- 3
0
votes
2 answers
How to copy to clipboard w/o os api using lua and ffi
How do you copy a value or string in lua? I’ve only found alternatives for the regular microsoft os api. For my use I do not have access to the os api and instead have access to ffi and steam panorama.
If possible I would also know how to get a…

Nepo
- 1
- 2
0
votes
1 answer
Using `riscv64-unknown-elf-g++` to link rust static lib failed
I try to use riscv64-unknown-elf-g++ which is rv64imac architecture to compile C code with rust static lib.
The simple example is https://github.com/zzhengzhuo/base_bin .
When I use riscv64-unknown-elf-gcc, it works well. But when I use…

user18014250
- 1
- 1
0
votes
0 answers
Is there a workaround for the fact that TypeId only works for 'static types?
I am giving C++ a Box containing a trait object, and then when I get that Box back from C++, I want to try to downcast it into a concrete type. However, I can't do it safely because the types I'm using are not (and cannot be) 'static, so…

laptou
- 6,389
- 2
- 28
- 59
0
votes
1 answer
Rust FFI - Dangling pointer
I work on a Rust library used, through C headers, in a Swift UI.
I can read from Swift in Rust, but I can't write right away to Swift (so from Rust) what I've just read.
--
Basically, I get to convert successfully in String an *const i8 saying hello…

Ontokrat
- 189
- 1
- 14