-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add Dart_NewClosure to dart_api.h #44083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If you really want to use Dart VM C API (see my note below though) you can do: class MyClosure extends NativeFieldWrapper2 {
// First native field would be Dart_ClosureCallback to call
// Second native field would be user_data.
void call(Object arg) native "MyClosure_call";
} Then you can create Note: I would however really-really discourage you from using API - FFI is the way forward. We have just kicked off a project to start shifting embedder bindings to FFI - starting with our own bindings see #43889. If we make enough progress on this in 2020 I can see us starting to deprecate parts of C API to shrink its surface. (/cc @mkustermann) |
I suspect this request doesn't come from normal C <-> Dart interaction but rather from the wish to perform synchronous isolate spawning. I've filed #44088 and will add an API for that. |
I looked into using FFI to return the value once the future is resolved. I don't think Dart FFI supports finding symbols in its own executable. All the documentation shows loading auxiliary shared libraries and loading symbols from them. My use case is Dart, compiled with AOT, calling into a C function, both linked into the Flutter shared library. I filed another issue related to this to document if we have a way for loading internal symbols #44126 |
Right now using symbols from executable is only possible if they are not stripped. In which case you can go through |
Thanks, I got this working with FFI. Creating the closure would have the benefit of attaching context data, the |
@gaaclarke any chance you would have some notes or a pointer to Flutter SDK code where you did this with FFI? |
@maks I don't think I ever used this in production code that I remember. I may have just been playing with The REPL sounds cool, does the Dart debugger already have something similar? If not it would be useful there. |
No worries at all @gaaclarke, I was just hoping to have myself a bit of time if there was already some examples I could crib off. And yes for sure, the VM Service does already handle expression eval very nicely and I am using it successfully in my repl package, but its statements where I got stuck and the initial approach of trying to handle them via hot-reload doesn't seem to work well. I just left a update on the Repl issue about why I was wanting to go down the Dart embedder API route to handle them. |
Looking through the dart_api.h file there doesn't seem to be an easy way to communicate data asynchronously back to the embedder environment. If we had an easy way to wrap a c function into a Dart closure it would be helpful.
proposed signature:
That will create a
void Function(dynamic)
closure.user_data
is just passed along to the callback.The text was updated successfully, but these errors were encountered: