-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
112 lines (96 loc) · 3.92 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>RustPython Demo</title>
<link href="styles.css" rel="stylesheet"></head>
<body>
<h1>RustPython Demo</h1>
<p>
RustPython is a Python interpreter written in Rust. This demo is
compiled from Rust to WebAssembly so it runs in the browser.<br>
Input your Python code below and click <kbd>Run</kbd>
(or <kbd>Ctrl+Enter</kbd>), or you can open up your
browser's devtools and play with <code>rp.pyEval('1 + 1')</code>
</p>
<div id="code-wrapper">
<textarea id="code">n1 = 0
n2 = 1
count = 0
until = 10
print(f"These are the first {until} numbers in the Fibonacci sequence:")
while count < until:
print(n1)
n1, n2 = n2, n1 + n2
count += 1
</textarea>
<select id="snippets">
<option
>asyncbrowser</option>
<option
>fetch</option>
<option
selected
>fibonacci</option>
<option
>fizzbuzz</option>
<option
>mandelbrot</option>
</select>
</div>
<button id="run-btn">Run ▷</button>
<div id="error"></div>
<h3>Standard Output</h3>
<textarea id="console" readonly>Loading...</textarea>
<h3>Interactive shell</h3>
<div id="terminal"></div>
<p>
Here's some info regarding the <code>rp.pyEval()</code>,
<code>rp.pyExec()</code>, and <code>rp.pyExecSingle()</code>
functions
</p>
<ul>
<li>
You can return variables from python and get them returned to
JS, with the only requirement being that they're serializable
with <code>json.dumps</code>.
</li>
<li>
You can pass an options object as the second argument to the
function:
<ul>
<li>
<code>stdout</code>: either a string with a css selector
to a textarea element or a function that receives a
string when the <code>print</code> function is called in
python. The default value is <code>console.log</code>.
</li>
<li>
<code>vars</code>: an object that will be available in
python as the variable <code>js_vars</code>. Only
functions and values that can be serialized with
<code>JSON.stringify()</code> will go through.
</li>
</ul>
</li>
<li>
JS functions that get passed to python will receive positional
args as positional args and kwargs as the
<code>this</code> argument
</li>
</ul>
<p>
Limited Interaction with browser is possible from Python by using
the <code>browser</code> module. Browser APIs such as
<code>alert()</code>, <code>confirm()</code>, <code>prompt()</code>
and <code>fetch()</code> are included in the module.
</p>
<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>
<script type="text/javascript" src="index.js"></script></body>
</html>