|
1 | 1 | <!DOCTYPE html> |
2 | 2 | <html> |
3 | | - <head> |
4 | | - <meta charset="utf-8"> |
5 | | - <title>RustPython Demo</title> |
6 | | - <style type="text/css" media="screen"> |
7 | | - textarea { |
8 | | - font-family: monospace; |
9 | | - } |
10 | | - |
11 | | - #code { |
12 | | - height: 35vh; |
13 | | - width: 95vw; |
14 | | - } |
15 | | - |
16 | | - #console { |
17 | | - height: 35vh; |
18 | | - width: 95vw; |
19 | | - } |
20 | | - |
21 | | - #run-btn { |
22 | | - width: 4em; |
23 | | - height: 2em; |
24 | | - font-size: 24px; |
25 | | - } |
26 | | - </style> |
27 | | - </head> |
28 | | - <body> |
29 | | - <h1>RustPython Demo</h1> |
30 | | - <p>RustPython is a Python interpreter writter in Rust. This demo is compiled from Rust to WebAssembly so it runs in the browser</p> |
31 | | - <p>Please input your python code below and click <kbd>Run</kbd>:</p> |
32 | | - <textarea id="code">n1 = 0 |
| 3 | + <head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <title>RustPython Demo</title> |
| 6 | + <link href="styles.css" rel="stylesheet"></head> |
| 7 | + <body> |
| 8 | + <h1>RustPython Demo</h1> |
| 9 | + <p> |
| 10 | + RustPython is a Python interpreter writter in Rust. This demo is |
| 11 | + compiled from Rust to WebAssembly so it runs in the browser.<br> |
| 12 | + Please input your Python code below and click <kbd>Run</kbd>, or you |
| 13 | + can open up your browser's devtools and play with |
| 14 | + <code>rp.pyEval('print("a")')</code> |
| 15 | + </p> |
| 16 | + <textarea id="code"> |
| 17 | +n1 = 0 |
33 | 18 | n2 = 1 |
34 | 19 | count = 0 |
35 | 20 | until = 10 |
36 | 21 |
|
37 | | -print("These are the first " + str(until) + " number in a Fibonacci sequence:") |
| 22 | +print("These are the first {} numbers in the Fibonacci sequence:".format(until)) |
38 | 23 |
|
39 | 24 | while count < until: |
40 | 25 | print(n1) |
41 | 26 | n1, n2 = n2, n1 + n2 |
42 | 27 | count += 1 |
43 | 28 | </textarea> |
44 | | - <button id="run-btn">Run ▷</button> |
45 | | - <script src="./bootstrap.js"></script> |
46 | | - <h3>Standard Output</h3> |
47 | | - <textarea id="console">Loading...</textarea> |
| 29 | + <button id="run-btn">Run ▷</button> |
| 30 | + <div id="error"></div> |
| 31 | + <h3>Standard Output</h3> |
| 32 | + <textarea id="console" readonly>Loading...</textarea> |
| 33 | + |
| 34 | + <p>Here's some info regarding the <code>rp.pyEval()</code> function</p> |
| 35 | + <ul> |
| 36 | + <li> |
| 37 | + You can return variables from python and get them returned to |
| 38 | + JS, with the only requirement being that they're serializable |
| 39 | + with <code>json.dumps</code>. |
| 40 | + </li> |
| 41 | + <li> |
| 42 | + You can pass an options object as the second argument to the |
| 43 | + function: |
| 44 | + <ul> |
| 45 | + <li> |
| 46 | + <code>stdout</code>: either a string with a css selector |
| 47 | + to a textarea element or a function that recieves a |
| 48 | + string when the <code>print</code> function is called in |
| 49 | + python. The default value is <code>console.log</code>. |
| 50 | + </li> |
| 51 | + <li> |
| 52 | + <code>vars</code>: an object that will be available in |
| 53 | + python as the variable <code>js_vars</code>. Only |
| 54 | + functions and values that can be serialized with |
| 55 | + <code>JSON.stringify()</code> will go through. |
| 56 | + </li> |
| 57 | + </ul> |
| 58 | + </li> |
| 59 | + <li> |
| 60 | + JS functions that get passed to python will recieve positional |
| 61 | + args as positional args and kwargs as the |
| 62 | + <code>this</code> argument |
| 63 | + </li> |
| 64 | + </ul> |
48 | 65 |
|
49 | | - <a href="https://github.com/RustPython/RustPython"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png" alt="Fork me on GitHub"></a> |
50 | | - </body> |
| 66 | + <a href="https://github.com/RustPython/RustPython"> |
| 67 | + <img |
| 68 | + style="position: absolute; top: 0; right: 0; border: 0;" |
| 69 | + src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png" |
| 70 | + alt="Fork me on GitHub" |
| 71 | + /> |
| 72 | + </a> |
| 73 | + <script type="text/javascript" src="index.js"></script></body> |
51 | 74 | </html> |
0 commit comments