Build a library usable for embedding & FFI #492
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Using a library via FFI is usually done via a shared library load. When I was attempting to embed HashLink via an FFI, I had a need for a shared library version of
hl
so that I could use the functions for loading and initializing.hl
bytecode. This PR adds make targets for such a library, plus exposing a few more methods necessary when looking up and calling objects as I've seen referenced in the community and issues here. Additionally, there is a thread-helper method I found necessary when calling from not just a single spot in the C stack. Currently, I make it build aslibhl-jit.so
, but I'm not married to the name. I originally was thinkinglibhl-embed.so
.Things not in this PR, but could be helpful for embedding via an FFI:
It may be helpful to also document how to integrate with the GC, that took me a while to figure out.
An entrypoint helper. It's a bit more verbose in non-C languages via FFI
Method lookup/calling helpers. This surprised me at the lack of helpers. Right now my FFI code looks like this for driving looking up methods:
I didn't implement these as I wanted to discuss them first, after a minimum basic solution (the PR right now).