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
I want to give my plugins access to stuff on the host's database. What I'd normally do, is pass my
Storestruct around, which contains methods that you can do to get access to the database. Of course I can't do this with plugins, as theStorecannot pass the memory boundary. So what I could do, is create aqueryfunction in my host, and expose that in the plugin runtime. Thatqueryfunction will still need to access myStore. In some programming languages, you might use some global context and take theStorefrom there, but that's not an option in Rust I think: I need to pass myStoreexplicitly to my newqueryfunction. 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
Storeit will need to get data from.What I think I need, is define something like this in my host:
But my protocol needs to have something like this:
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. Thiscontextis 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 thisContextdoes 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 usingfp-bindgen, such as myStorein the example above.note: @Zagitta has already let me know in Discord that they're working on a prototype to do something like this