Skip to content

Commit f187c77

Browse files
iabdalkaderdpgeorge
authored andcommitted
shared/runtime/pyexec: Add helper function to execute a vstr.
Add `pyexec_vstr()` to execute Python code from a vstr source. Signed-off-by: iabdalkader <[email protected]>
1 parent dbda43b commit f187c77

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

shared/runtime/pyexec.c

+5
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,11 @@ int pyexec_frozen_module(const char *name, bool allow_keyboard_interrupt) {
720720
}
721721
#endif
722722

723+
int pyexec_vstr(vstr_t *str, bool allow_keyboard_interrupt) {
724+
mp_uint_t exec_flags = allow_keyboard_interrupt ? 0 : EXEC_FLAG_NO_INTERRUPT;
725+
return parse_compile_execute(str, MP_PARSE_FILE_INPUT, exec_flags | EXEC_FLAG_SOURCE_IS_VSTR);
726+
}
727+
723728
#if MICROPY_REPL_INFO
724729
mp_obj_t pyb_set_repl_info(mp_obj_t o_value) {
725730
repl_display_debugging_info = mp_obj_get_int(o_value);

shared/runtime/pyexec.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ int pyexec_friendly_repl(void);
4242
int pyexec_file(const char *filename);
4343
int pyexec_file_if_exists(const char *filename);
4444
int pyexec_frozen_module(const char *name, bool allow_keyboard_interrupt);
45+
int pyexec_vstr(vstr_t *str, bool allow_keyboard_interrupt);
4546
void pyexec_event_repl_init(void);
4647
int pyexec_event_repl_process_char(int c);
4748
extern uint8_t pyexec_repl_active;

0 commit comments

Comments
 (0)