...
This commit is contained in:
blueloveTH 2023-04-24 17:47:08 +08:00
parent a97149778a
commit 4e74d66768
3 changed files with 11 additions and 3 deletions

View File

@ -13,4 +13,12 @@ You need to use the C++ `new` operator to create a `VM` instance.
```cpp ```cpp
VM* vm = new VM(); VM* vm = new VM();
``` ```
The constructor can take 2 extra parameters.
#### `VM(bool use_stdio=true, bool enable_os=true)`
+ `use_stdio`, if `true`, the `print()` function outputs string to `stdout`. Error messages will be send to `stderr`; If `false`, they will be sent to an internal buffer. In the latter case, you need to read them via `read_output` manually.
+ `enable_os`, whether to enable OS-related features or not. This setting controls the availability of some priviledged modules such os `io` and `os` as well as builtin function `open`.

View File

@ -14,7 +14,7 @@ links:
link: "" link: ""
- text: "Live Demo" - text: "Live Demo"
icon: play icon: play
link: "./static/web/index.html" link: "https://pocketpy.dev/static/web/"
target: blank target: blank
- text: "Github" - text: "Github"
icon: mark-github icon: mark-github

View File

@ -113,7 +113,7 @@ var Module = {
term.write(text + "\r\n"); term.write(text + "\r\n");
}, },
'onRuntimeInitialized': function(text) { 'onRuntimeInitialized': function(text) {
var vm = Module.ccall('pkpy_new_vm', 'number', [], []); var vm = Module.ccall('pkpy_new_vm', 'number', ['boolean', 'boolean'], [true, true]);
repl = Module.ccall('pkpy_new_repl', 'number', ['number'], [vm]); repl = Module.ccall('pkpy_new_repl', 'number', ['number'], [vm]);
term.write(need_more_lines ? "... " : ">>> "); term.write(need_more_lines ? "... " : ">>> ");
}, },