8000 emscripten: restructure npm package: - main.js is now importable, co… · matthewelse/micropython@7e03f6a · GitHub
[go: up one dir, main page]

Skip to content

Commit 7e03f6a

Browse files
committed
emscripten: restructure npm package: - main.js is now importable, containing an init() and a run(code) function - repl.js can now be run, producing a REPL
1 parent 0b4c353 commit 7e03f6a

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

emscripten/main.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11

2-
const repl = require('repl');
32
const mpy = require('./build/firmware.js');
43

5-
function mpy_eval(cmd, context, filename, callback) {
6-
callback(null, mpy.ccall('mp_js_run', 'null', ['string'], [cmd]));
4+
module.exports.run = function(code) {
5+
mpy.ccall('mp_js_run', 'null', ['string'], [code]);
76
}
87

9-
10-
console.log("MicroPython on asmjs with emscripten");
11-
console.log("Type \"help()\" for more information.");
12-
13-
mpy.ccall('mp_js_init', 'null', [], []);
14-
repl.start({prompt: '> ', eval: mpy_eval});
8+
module.exports.init = function() {
9+
mpy.ccall('mp_js_init', 'null', [], []);
10+
}
1511

emscripten/repl.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
const repl = require('repl');
3+
const mpy = require('./main.js');
4+
5+
function mpy_eval(cmd, context, filename, callback) {
6+
callback(null, mpy.run(cmd));
7+
}
8+
9+
10+
console.log("MicroPython on asmjs with emscripten");
11+
console.log("Type \"help()\" for more information.");
12+
13+
mpy.init();
14+
repl.start({prompt: '> ', eval: mpy_eval});
15+

0 commit comments

Comments
 (0)
0