Skip to content

How to use callback functions? #118

Description

@yyon

Hello,
I'm trying to call a function in ObjC that takes a callback function, and I'm hoping to have that call back to a rust function. The function I'm trying to call is this one: https://developer.apple.com/documentation/webkit/wkwebview/1415017-evaluatejavascript?language=objc.

When I pass null to the callback function, it works:

            let callback_pointer = std::ptr::null::<*const std::ffi::c_void>(); // *const *const core:ffi::c_void
            let _: id = objc::msg_send![controller, evaluateJavaScript:javascript_string completionHandler:callback_pointer];
            

I tried this:

> struct NSError(id);
> extern fn javascript_callback_macos(value: id, error: NSError) {
>     println!("javascript_callback_macos");
> }
> ...
> let _: id = objc::msg_send![controller, evaluateJavaScript:javascript_string completionHandler:javascript_callback_macos as extern fn(id, NSError)];

but it crashes without an error message

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions