mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 19:50:30 +01:00
webassembly: Implement replInit() and replProcessChar().
This is the JavaScript API for starting and running a REPL. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -150,6 +150,27 @@ export async function loadMicroPython(options) {
|
||||
);
|
||||
return proxy_convert_mp_to_js_obj_jsside_with_free(value);
|
||||
},
|
||||
replInit() {
|
||||
Module.ccall("mp_js_repl_init", "null", ["null"]);
|
||||
},
|
||||
replProcessChar(chr) {
|
||||
return Module.ccall(
|
||||
"mp_js_repl_process_char",
|
||||
"number",
|
||||
["number"],
|
||||
[chr],
|
||||
);
|
||||
},
|
||||
// Needed if the GC/asyncify is enabled.
|
||||
async replProcessCharWithAsyncify(chr) {
|
||||
return Module.ccall(
|
||||
"mp_js_repl_process_char",
|
||||
"number",
|
||||
["number"],
|
||||
[chr],
|
||||
{ async: true },
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -191,11 +212,11 @@ async function runCLI() {
|
||||
});
|
||||
|
||||
if (repl) {
|
||||
mp_js_init_repl();
|
||||
mp.replInit();
|
||||
process.stdin.setRawMode(true);
|
||||
process.stdin.on("data", (data) => {
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
mp_js_process_char(data[i]).then((result) => {
|
||||
mp.replProcessCharWithAsyncify(data[i]).then((result) => {
|
||||
if (result) {
|
||||
process.exit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user