Skip to content
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

Accessing host context from within runtime - passing arguments to function invocations #98

Open
joepio opened this issue Apr 4, 2022 · 0 comments
Labels
enhancement New feature or request rust-runtime

Comments

@joepio
Copy link
Contributor

joepio commented Apr 4, 2022

I want to give my plugins access to stuff on the host's database. What I'd normally do, is pass my Store struct around, which contains methods that you can do to get access to the database. Of course I can't do this with plugins, as the Store cannot pass the memory boundary. So what I could do, is create a query function in my host, and expose that in the plugin runtime. That query function will still need to access my Store. In some programming languages, you might use some global context and take the Store from there, but that's not an option in Rust I think: I need to pass my Store explicitly to my new query function. But how can I do this?

However, I have no idea on how I can then pass some context to my runtime, so that my runtime knows which Store it will need to get data from.

What I think I need, is define something like this in my host:

fn my_complex_imported_function(query: Query, host_store: Store) -> ComplexHostToGuest {
    host_store.perform_query(query)
}

But my protocol needs to have something like this:

fn my_complex_imported_function(query: Query) -> ComplexHostToGuest

See what I'm getting at? Maybe I'm approaching this all wrong, but I fail to see how I can pass something to host functions from the host itself.

Maybe Runtime::new() could take a Context argument, which the user defines. This context is then passed to every function in the host's context, as the first argument. Not sure how difficult this is, but seems reasonable, as the user will have the context known when instantiating the Runtime. Note that this Context does not need to be available in the Runtime itself, but only by the host. This means that we could pass arguments that are not properly mapped using fp-bindgen, such as my Store in the example above.

note: @Zagitta has already let me know in Discord that they're working on a prototype to do something like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rust-runtime
Projects
None yet
Development

No branches or pull requests

2 participants