Is there a way to run a multi line python script from memory (not from a File, since
my embedded op system doesn't support this and also don't need it) ?
Is there a form that takes a char* of the multi line python script itself
versus a file name ?
I don't have files, just the script in memory (hard coded in a const char*
for now, but could also be received from a socket at some point in the near future)
This seems like a straight forward need, but I haven't found any good examples.
Here is a simple example of the kind of script I need to run:
Code: Select all
count = 0
while count < 5:
print count
count += 1
int pyexec_file(const char *filename);
Here is what I would like to do, though it does not work
(note, that I have tried calling do_str() by passing in the entire string with carriage returns, as listed in many main.c files in the micropython project, but it doesn't work and get the following error:
Code: Select all
Traceback (most recent call last):
File "<stdin>"
SyntaxError: invalid syntax
Code: Select all
print('hello world')
Code: Select all
print('hello world!', list(x+1 for x in range(10)), end='eol\\n')
and it also fails to execute.
Code: Select all
int stack_dummy;
stack_top = (char*)&stack_dummy;
#if MICROPY_ENABLE_GC
gc_init(heap, heap + sizeof(heap));
#endif
mp_init();
const char* src = "count = 0\n"
"while count < 5:\n"
" print count\n"
" count += 1\n";
char* pChar = src;
while(*pChar != '\0')
{
pyexec_event_repl_process_char(*pChar);
pChar++;
}
mp_deinit();