From 914e2be5f52f19a995649bed047e9d2d814a6a42 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 23 Feb 2019 22:36:17 +0200 Subject: Add WIP Python REPL interface - Requires Python >= 3.0.0 and linenoise or linenoise-ng - WIP: not built into the browser itself --- src/cli/cli.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/cli/meson.build | 4 ++++ 2 files changed, 55 insertions(+) create mode 100644 src/cli/cli.cpp create mode 100644 src/cli/meson.build (limited to 'src/cli') diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp new file mode 100644 index 0000000..ae3795e --- /dev/null +++ b/src/cli/cli.cpp @@ -0,0 +1,51 @@ +#include +#include +//#include +#include +#include + +int main(int argc, char** argv) +{ + printf("cli test application\n"); + + wchar_t *program = Py_DecodeLocale(argv[0], NULL); + if (program == NULL) { + fprintf(stderr, "Fatal error: cannot decode argv[0]\n"); + exit(1); + } + + // inform the interpreter about paths to run-time libraries + Py_SetProgramName(program); /* optional but recommended */ + + + // Initialize the python interpreter + Py_Initialize(); + + PyRun_SimpleString("print('Python interpreter ready')\n"); + + const char* prompt = "poi> "; + + while(true) { + char *cmd = linenoise(prompt); + + if(cmd == nullptr || *cmd == '\0') { + printf("break\n"); + free(cmd); + break; + } + + //printf("echo(%i):'%s'\n", strlen(cmd), cmd); + PyRun_SimpleString(cmd); + free(cmd); + } + + // finalize the interpreter + if (Py_FinalizeEx() < 0) { + exit(120); + } + + // + PyMem_RawFree(program); + + return 0; +} diff --git a/src/cli/meson.build b/src/cli/meson.build new file mode 100644 index 0000000..298e1db --- /dev/null +++ b/src/cli/meson.build @@ -0,0 +1,4 @@ +cli_demo = executable('cli', install: false, dependencies: [ optional_deps ], + sources: [ 'cli.cpp' ] +) + -- cgit v1.2.1