aboutsummaryrefslogtreecommitdiff
path: root/src/cli/cli.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2019-02-23 22:36:17 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2019-02-23 22:36:17 +0200
commit914e2be5f52f19a995649bed047e9d2d814a6a42 (patch)
tree53b82dc4d04acdc4522b695e8aec972913bd832c /src/cli/cli.cpp
parentSubWindow: closing tab restores previous index (diff)
downloadsmolbote-914e2be5f52f19a995649bed047e9d2d814a6a42.tar.xz
Add WIP Python REPL interface
- Requires Python >= 3.0.0 and linenoise or linenoise-ng - WIP: not built into the browser itself
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;
+}