Skip to content

implement () -> () as Runnable downcalls and upcalls #100

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

Merged
merged 2 commits into from
Oct 22, 2024

Conversation

ktoso
Copy link
Collaborator

@ktoso ktoso commented Oct 22, 2024

resolves #99

Now we're able to

        CountDownLatch countDownLatch = new CountDownLatch(3);

        ExampleSwiftLibrary.globalCallMeRunnable(new Runnable() {
            @Override
            public void run() {
                countDownLatch.countDown();
            }
        });
        assertEquals(2, countDownLatch.getCount());

        ExampleSwiftLibrary.globalCallMeRunnable(() -> countDownLatch.countDown());
        assertEquals(1, countDownLatch.getCount());

        ExampleSwiftLibrary.globalCallMeRunnable(countDownLatch::countDown);
        assertEquals(0, countDownLatch.getCount());

when given a

public func globalCallMeRunnable(run: () -> ())

"""
FunctionDescriptor \(desc) = FunctionDescriptor.ofVoid();
MethodHandle \(handle) = MethodHandles.lookup()
.findVirtual(Runnable.class, "run",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make this more reusable and take the name from self but let's do that later

@ktoso ktoso merged commit 6964e71 into swiftlang:main Oct 22, 2024
11 checks passed
@ktoso ktoso deleted the wip-jextract-callbacks branch October 22, 2024 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

jextract: Support callbacks into JVM by passing Runnable as () -> () in jextracted wrappers
2 participants