From 8d78c67d0b82f05fc69d3cab6b3c009043e70c80 Mon Sep 17 00:00:00 2001 From: Shing Lyu Date: Mon, 3 Dec 2018 20:47:30 +0100 Subject: [PATCH] Created a demo page so user can try their code online --- wasm/app/index.html | 19 +++++++++++++++++++ wasm/app/index.js | 12 +++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/wasm/app/index.html b/wasm/app/index.html index 00f0d24078..b7a992f9c1 100644 --- a/wasm/app/index.html +++ b/wasm/app/index.html @@ -3,8 +3,27 @@ RustPython Starter Application + +

RustPython Demo

+

Please input your python code below and click Run:

+ + +

Open the browser console (Ctrl+Shift+I or F12) to see the output

diff --git a/wasm/app/index.js b/wasm/app/index.js index 10797d6886..f308a1aea8 100644 --- a/wasm/app/index.js +++ b/wasm/app/index.js @@ -1,3 +1,13 @@ import * as rp from "rustpython_wasm"; -rp.run_code("print('Hello Python!')\n"); +function runCodeFromTextarea(_) { + const code = document.getElementById('code').value; + if (!code.endsWith('\n')) { // HACK: if the code doesn't end with newline it crashes. + rp.run_code(code + '\n'); + return; + } + rp.run_code(code); +} +document.getElementById('run-btn').addEventListener('click', runCodeFromTextarea); + +runCodeFromTextarea(); // Run once for demo