|
1 | | -For using repl and debugging pygbag games |
2 | | -just use http://localhost:8000/#debug instead of just http://localhost:8000 |
| 1 | +pygbag comes with an interactive Python-like REPL that can be used for debugging. |
| 2 | + |
| 3 | +## to open |
| 4 | +To open the REPL, visit `http://localhost:8000/#debug` instead of just `http://localhost:8000`. |
| 5 | + |
| 6 | +To get debugger at runtime, open the [javascript console](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Tools_and_setup/What_are_browser_developer_tools#the_javascript_console) and run `debug()` by typing in `debug()` followed by pressing enter. |
| 7 | + |
| 8 | +## to use |
| 9 | +The REPL is a Python REPL that has loaded the project. This means if your pygbag main file includes a `main() function`, calling `type(main)` will return `<class 'function'>` instead of a `NameError`. |
| 10 | + |
| 11 | +It also implements a variety of shell-like commands, defined in the [shell](https://github.com/pygame-web/pygbag/blob/72b34546e23086c78f5b193c05e3e961b807f214/src/pygbag/support/cpythonrc.py#L266) class, that are reminiscent of shell languages common on Linux systems. These can be used in the REPL. |
| 12 | +For example, |
| 13 | +```bash |
| 14 | +>>> cat main.py |
| 15 | +``` |
| 16 | +will dump the binary contents of `main.py` into the REPL, if `main.py` exists in your pygbag project directory. |
| 17 | + |
| 18 | +Other helpful commands are available. For example,`rx` takes a list of files and downloads them from the browser's filesystem to a user's filesystem. For example, |
| 19 | +```bash |
| 20 | +>>> rx main.py assets/image.png assets/otherimage.png |
| 21 | +``` |
| 22 | +will try to download the given three files. |
| 23 | + |
| 24 | +## Python versus browser logging |
| 25 | +`print` statements will write to this REPL instead of the browser's console. |
| 26 | + |
| 27 | +To write to the browser's console instead, use `platform.console.log`. For example, |
| 28 | +```py |
| 29 | +import sys, platform |
| 30 | +if sys.platform == "emscripten": |
| 31 | + platform.console.log("logged message") |
| 32 | +``` |
| 33 | + |
| 34 | + |
| 35 | + |
3 | 36 |
|
4 | | -to get debugger at runtime use ctrl+shift+i to pop up javascript console from pygbag page tab and type : debug() |
5 | | -followed by enter. |
6 | 37 |
|
7 | 38 |
|
8 | 39 | [edit this page](https://github.com/pygame-web/pygame-web.github.io/edit/main/wiki/pygbag-debug/README.md) |
0 commit comments