aboutsummaryrefslogtreecommitdiff
path: root/src/cli/cli.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/cli.cpp')
-rw-r--r--src/cli/cli.cpp51
1 files changed, 51 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+//#include <string.h>
+#include <linenoise.h>
+#include <Python.h>
+
+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;
+}