aboutsummaryrefslogtreecommitdiff
path: root/src/cli
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
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')
-rw-r--r--src/cli/cli.cpp51
-rw-r--r--src/cli/meson.build4
2 files changed, 55 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;
+}
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' ]
+)
+