dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
157 stars 44 forks source link

[ffigen] Variadic arguments with function types. #1732

Open dcharkes opened 2 hours ago

dcharkes commented 2 hours ago

@dcharkes is there a way to do variadic arguments that are functions? trying to generate libcurl bindings

CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...);

and a version of the function accepts a

static size_t curl_callback(char *data, size_t size, size_t nmemb, void *clientp)

 functions:
    variadic-arguments:
      curl_easy_setopt:
        - [ 'long' ]
        - [ 'char*' ]
        - [ 'curl_off_t' ]
        - [ 'size_t curl_callback(char *data, size_t size, size_t nmemb, void *clientp)' ] <- this is what i want to somehow represent

Originally posted by @kingwill101 in https://github.com/dart-lang/native/issues/238#issuecomment-2439845973

@liamappelbe I suppose we don't support defining new types yet?

Now that we're starting to move into the visitor-world instead of yaml-config-world, could we conceivably add something for that?

@kingwill101 A possible work around would be to make a typedef for the function type in a separate header file, and add that header file to your FFIgen config, and use the typedef name as the type.

kingwill101 commented 2 hours ago

@kingwill101 A possible work around would be to make a typedef for the function type in a separate header file, and add that header file to your FFIgen config, and use the typedef name as the type.

I believe I tried that approach and it didn't work. Will give it another shot