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

Where to ask question about wasmi? #166

Closed
andrewdavidmackenzie opened this issue Jan 28, 2019 · 3 comments
Closed

Where to ask question about wasmi? #166

andrewdavidmackenzie opened this issue Jan 28, 2019 · 3 comments

Comments

@andrewdavidmackenzie
Copy link

Is there a better place then here, in issues, to ask questions about using wasmi?

In particular, I have functions like this:

extern crate serde_json;

use serde_json::Value as JsonValue;
use serde_json::Value::String as JsonString;

#[no_mangle]
pub extern "C" fn run(mut inputs: Vec<Vec<JsonValue>>) -> (Option<JsonValue>, bool) {

written in rust, compiled to wasm, that I then want to call elsewhere (after loading the ModuleRef).

Is there any example code or hints on how to convert such complex input and output types to and from RuntimeValues, and call functions with that signature?

        let res = module.invoke_export("run", &[RuntimeValue::from(inputs)],
                                  &mut NopExternals).unwrap().unwrap();

Thanks for any help here or pointers to where better to ask such question.

@pepyakin
Copy link
Collaborator

That's a great question!

First, I'd recommend against using Vec and even a tuple, since they are Rust types which don't have stable ABI representation. I'd recommend even more so against using JsonValue since it's representation additionally depends on serde package.

Basically you would need to write wrappers that use only ABI stable values and can be safely passed via ABI boundary.

It is hard to recommend anything specific, but it looks like you deal with some JS input and JS output. So what you could do is some how allocate a buffer of memory in the wasm sandbox, then copy JS serialized memory into the allocated buffer and then call the entrypoint function with a pointer to the buffer. You might want to construct a slice from the input buffer.

Then you do approximately the same, in the reverse direction when you are returning the data.

The best option to reach us would be using Riot on Parity Wasm public channel.

@andrewdavidmackenzie
Copy link
Author

andrewdavidmackenzie commented Jan 29, 2019 via email

@andrewdavidmackenzie
Copy link
Author

Something along the lines of this:

http://timryan.org/2019/01/22/exporting-serde-types-to-typescript.html

but instead of emitting a typescript type definition, it would generate the code to assemble the RuntimeValues to pass to the module_ref.invoke_export() method?

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

No branches or pull requests

2 participants