Skip to content

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