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

Client-side interactive terminal for WASM #374

Open
peterjoel opened this issue Aug 3, 2018 · 4 comments
Open

Client-side interactive terminal for WASM #374

peterjoel opened this issue Aug 3, 2018 · 4 comments
Labels
enhancement Something new the playground could do help wanted Not immediately going to be prioritized — ask for mentoring instructions!

Comments

@peterjoel
Copy link

It would be cool to be able to write Rust code for a WASM target and then execute it immediately within the web browser. A simple terminal could be made which supports calling methods and viewing the output.

Some background from Lukas Kalbertodt:
https://chat.stackoverflow.com/transcript/message/43471308#43471308

Regarding WASM. I think the way to go is certainly wasm32-unknown-unknown. And I think wasm-bindgen is also the way to go. As you already said, a super minimal terminal is already enough. You certainly wouldn't let the wasm thing access everything on the playground. So the only thing you (as the environment) need to provide is a print(&str) function.
The user can (and is reminded to do so) add a #[wasm_bindgen] extern { fn print(&str); } to their code.
Since we're talking about wasm32-unknown-unknown, the crate is compiled as library anyway. So the playground can decide how the main function would look like. So you could require that there is a global fn main(input: String) or something like that. You would call that function with something the user typed in a text box. Just as minimal example.
So it would require some integration with wasm-bindgen, some good diagnostic for telling the user about how the main() should look and that they should add this extern { print } block. Some JS code to load the wasm file from the server. But apart from that, I think this should absolutely be possible.

@shepmaster shepmaster added enhancement Something new the playground could do help wanted Not immediately going to be prioritized — ask for mentoring instructions! labels Aug 3, 2018
@shepmaster
Copy link
Member

require that there is a global fn main(input: String)

diagnostic for telling the user about how the main() should look

See also #323 which has the idea of "templates"

@titaneric
Copy link

Hi, I am interested to implement this feature and start to work on it.
This feature could be used in mdBook to write the interactive tutorial for wasm-bindgen, yew and seed framework.

@richardanaya
Copy link

Even a very minimalistic js-fiddle like setup that let's us call functions of the wasm with javascript would be huge.

@titaneric
Copy link

Update the latest work so far. I already tested on mdBook and rust-playground will work on it too!

2021-04-01-15-01-20-2.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something new the playground could do help wanted Not immediately going to be prioritized — ask for mentoring instructions!
Projects
None yet
Development

No branches or pull requests

4 participants