Skip to content

Commit 0785b24

Browse files
committed
Deploy RustPython/demo to github.com/RustPython/demo.git:master
1 parent e19b7ff commit 0785b24

File tree

9 files changed

+438
-39
lines changed

9 files changed

+438
-39
lines changed

1.bootstrap.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

1.index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

2.index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

7de85b250d4671f7b1b3.module.wasm

-2.31 MB
Binary file not shown.

bootstrap.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

d4264ca440b6ad489415.module.wasm

2.64 MB
Binary file not shown.

index.html

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,74 @@
11
<!DOCTYPE html>
22
<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
3318
n2 = 1
3419
count = 0
3520
until = 10
3621

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))
3823

3924
while count < until:
4025
print(n1)
4126
n1, n2 = n2, n1 + n2
4227
count += 1
4328
</textarea>
44-
<button id="run-btn">Run &#9655;</button>
45-
<script src="./bootstrap.js"></script>
46-
<h3>Standard Output</h3>
47-
<textarea id="console">Loading...</textarea>
29+
<button id="run-btn">Run &#9655;</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>
4865

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>
5174
</html>

0 commit comments

Comments
 (0)