FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

webprompt: display return value, remove spurious warnings · python-emscripten/python@2ade4a8 · GitHub

Repository navigation

Commit 2ade4a8

Browse files
committed
webprompt: display return value, remove spurious warnings
1 parent c224afe commit 2ade4a8

4 files changed

Lines changed: 31 additions & 12 deletions

File tree

‎2.7.10/webprompt-main.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,23 @@
99
* offered as-is, without any warranty.
1010
*/
1111

12-
#include <emscripten.h>
1312
#include <Python.h>
1413
PyMODINIT_FUNC initemscripten(void);
1514

1615
int main(int argc, char**argv) {
17-
Py_OptimizeFlag = 2; // look for .pyo rather than .pyc
18-
Py_InitializeEx(0); // get rid of 'Calling stub instead of sigaction()'
16+
Py_OptimizeFlag = 2; // look for .pyo rather than .pyc
17+
Py_FrozenFlag = 1; // drop <exec_prefix> warnings
18+
Py_VerboseFlag = 1; // trace modules loading
19+
Py_InitializeEx(0); // 0 = get rid of 'Calling stub instead of sigaction()'
1920
static struct _inittab builtins[] = { {"emscripten", initemscripten}, };
2021
PyImport_ExtendInittab(builtins);
2122
return 0;
2223
}
24+
25+
// Run a line *and* display the result
26+
// PyRun_StringFlags only returns a non-None object with Py_eval_input (no 'print' support)
27+
// PyRun_InteractiveOne always reads stdin even with another 'fp', so we redirect stdin
28+
void pyruni() {
29+
freopen("/tmp/input.py", "rb", stdin);
30+
PyRun_InteractiveOne(stdin, "<stdin>");
31+
}

‎2.7.10/webprompt-shell.html‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
<hr/>
6666
<textarea class="emscripten" id="output" rows="8"></textarea>
67-
<input type="text" class="emscripten" id="input" name="text" value="print({'hello':'world'})"></input>
67+
<input type="text" class="emscripten" id="input" name="text" value="{'hello':'world'}"></input>
6868
<hr>
6969

7070
<script type='text/javascript'>
@@ -160,26 +160,29 @@
160160
if (ev.key === 'Enter') {
161161
Module.print('>>> ' + input.value);
162162

163-
// Execute Python code
164-
Module.cwrap('PyRun_SimpleString', 'number', ['string'])(input.value);
163+
// Execute Python code
164+
// Module.cwrap('PyRun_SimpleString', 'number', ['string'])(input.value);
165165
// or: Module.ccall('PyRun_SimpleString', 'number', ['string'], [input.value]);
166+
FS.writeFile('/tmp/input.py', input.value + '\n')
167+
Module.ccall('pyruni');
166168

167169
hist[hist.length-1] = input.value;
168-
hist.push('');
169-
hist_index = hist.length - 1;
170+
hist.push('');
171+
hist_index = hist.length - 1;
170172
input.value = '';
171173
} else if (ev.key === 'ArrowUp') {
172174
hist[hist_index] = input.value;
173-
hist_index = (hist_index > 0) ? hist_index-1 : hist_index;
175+
hist_index = (hist_index > 0) ? hist_index-1 : hist_index;
174176
input.value = hist[hist_index];
175177
} else if (ev.key === 'ArrowDown') {
176178
hist[hist_index] = input.value;
177-
hist_index = (hist_index < hist.length-1) ? hist_index+1 : hist_index;
179+
hist_index = (hist_index < hist.length-1) ? hist_index+1 : hist_index;
178180
input.value = hist[hist_index];
179181
}
180182
};
181183
input.focus();
182184
</script>
185+
<script type='text/javascript' src="pythonhome-data.js"></script>
183186

184187
{{{ SCRIPT }}}
185188
</body>

‎2.7.10/webprompt.sh‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ mkdir -p $BUILD
1919

2020
cython ../emscripten.pyx -o $BUILD/emscripten.c
2121
emcc $BUILD/emscripten.c -o $BUILD/emscripten.bc -I $INSTALLDIR/include/python2.7
22+
PREFIX=$INSTALLDIR OUTDIR=$BUILD ./package-pythonhome.sh
2223
emcc -o $BUILD/webprompt.html \
2324
webprompt-main.c $BUILD/emscripten.c \
2425
-I$INSTALLDIR/include/python2.7 -L$INSTALLDIR/lib -lpython2.7 \
2526
-s EMULATE_FUNCTION_POINTER_CASTS=1 \
2627
-s USE_ZLIB=1 \
2728
-s TOTAL_MEMORY=256MB \
28-
--preload-file $INSTALLDIR/lib/python2.7@/lib/python2.7 \
29+
-s FORCE_FILESYSTEM=1 \
2930
--shell-file webprompt-shell.html \
30-
-s EXPORTED_FUNCTIONS="['_main', '_malloc', '_Py_Initialize', '_PyRun_SimpleString']" \
31+
-s EXPORTED_FUNCTIONS="['_main', '_malloc', '_Py_Initialize', '_PyRun_SimpleString', '_pyruni']" \
3132
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]'
33+
34+
# cython ../mock/emscripten.pyx -o t/mock.c
35+
# gcc -g -I build/hostpython/include/python2.7 -L build/hostpython/lib/ t/mock.c webprompt-main.c -lpython2.7 -ldl -lm -lutil -lz
36+
# PYTHONHOME=build/hostpython/ ./a.out

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Usage:
1111

1212
See for instance [RenPyWeb](https://github.com/renpy/renpyweb).
1313

14+
Web demo: <https://www.beuc.net/python-emscripten/demo/>
15+
1416
Mirrors:
1517

1618
- <https://gitlab.com/python-emscripten/python>

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL