Skip to content

Commit c85d3d5

Browse files
committed
Merge pull request bbcmicrobit#265 from dpgeorge/initial-script-execution
Only execute the initial script if in friendly-REPL mode.
2 parents cb61296 + af6a69c commit c85d3d5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

source/microbit/mprun.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,16 @@ void mp_run(void) {
105105
readline_init0();
106106
microbit_init();
107107

108-
if (APPENDED_SCRIPT->header[0] == 'M' && APPENDED_SCRIPT->header[1] == 'P') {
109-
// run appended script
110-
do_strn(APPENDED_SCRIPT->str, APPENDED_SCRIPT->len);
111-
} else if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
112-
// from microbit import *
113-
mp_import_all(mp_import_name(MP_QSTR_microbit, mp_const_empty_tuple, MP_OBJ_NEW_SMALL_INT(0)));
108+
// Only run initial script (or import from microbit) if we are in "friendly REPL"
109+
// mode. If we are in "raw REPL" mode then this will be skipped.
110+
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
111+
if (APPENDED_SCRIPT->header[0] == 'M' && APPENDED_SCRIPT->header[1] == 'P') {
112+
// run appended script
113+
do_strn(APPENDED_SCRIPT->str, APPENDED_SCRIPT->len);
114+
} else {
115+
// from microbit import *
116+
mp_import_all(mp_import_name(MP_QSTR_microbit, mp_const_empty_tuple, MP_OBJ_NEW_SMALL_INT(0)));
117+
}
114118
}
115119

116120
for (;;) {

0 commit comments

Comments
 (0)