mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10:17 +00:00
...
This commit is contained in:
parent
6b25aae3f7
commit
db2492829b
@ -3,7 +3,7 @@ title: VM
|
||||
icon: dot
|
||||
order: 10
|
||||
---
|
||||
#### `VM* pkpy_new_vm(bool use_stdio)`
|
||||
#### `VM* pkpy_new_vm()`
|
||||
|
||||
Create a virtual machine.
|
||||
|
||||
@ -27,12 +27,4 @@ Run a given source on a virtual machine.
|
||||
Get a global variable of a virtual machine.
|
||||
|
||||
Return `__repr__` of the result.
|
||||
If the variable is not found, return `nullptr`.
|
||||
|
||||
#### `char* pkpy_vm_read_output(VM* vm)`
|
||||
|
||||
Read the standard output and standard error as string of a virtual machine.
|
||||
The `vm->use_stdio` should be `false`.
|
||||
After this operation, both stream will be cleared.
|
||||
|
||||
Return a json representing the result.
|
||||
If the variable is not found, return `nullptr`.
|
@ -56,14 +56,12 @@ You need to use the C++ `new` operator to create a `VM` instance.
|
||||
VM* vm = new VM();
|
||||
```
|
||||
|
||||
The constructor can take 2 extra parameters.
|
||||
The constructor can take 1 extra parameters.
|
||||
|
||||
#### `VM(bool use_stdio=true, bool enable_os=true)`
|
||||
#### `VM(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`.
|
||||
|
||||
|
||||
When you are done with the `VM` instance, you need to use the C++ `delete` operator to free the memory.
|
||||
|
||||
```cpp
|
||||
|
@ -113,7 +113,7 @@ var Module = {
|
||||
term.write(text + "\r\n");
|
||||
},
|
||||
'onRuntimeInitialized': function(text) {
|
||||
var vm = Module.ccall('pkpy_new_vm', 'number', ['boolean', 'boolean'], [true, true]);
|
||||
var vm = Module.ccall('pkpy_new_vm', 'number', ['boolean'], [true]);
|
||||
repl = Module.ccall('pkpy_new_repl', 'number', ['number'], [vm]);
|
||||
term.write(need_more_lines ? "... " : ">>> ");
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user