add a rust API for defining struct types and ffi functions from safe rust without loading a dynamic library #3145
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.
primarily adds functions
Machine::register_structandMachine::register_functionMachine::register_struct
This is the rust counterpart to to
ffi:foreign_struct/2in prolog.It allows registering a struct that implements the unsafe
CustomFfiStructtrait.Machine::register_function
There is no prolog equivalent.
Related to
use_foreign_module/2, tough without loading a dynamic/shared library and one function per call.https://github.com/Skgland/scryer-prolog/blob/c1a79f3598c8bd56f7d5a8b3769548ee1bd17cea/tests/scryer/ffi.rs#L373-L388
Todo
Help wanted
library(ffi)(or make loading it unnecessary), see https://github.com/Skgland/scryer-prolog/blob/c1a79f3598c8bd56f7d5a8b3769548ee1bd17cea/tests/scryer/ffi.rs#L373ffi:assert_predicate()should be created, seeFuture Work
CustomFfiStructsomething like
ffi:call(FnPtr, ArgTypes, RetType, Args, Ret)(suggestion for a better name appreciated) after this PR most things needed should be in place alreadyuse_foreign_moduleto have seperate predicates forffi:call/5abovee.g. allow loading plugins that all define the same entry-point/callback functions