From 42c03e2ad6110625b54c8aab5960a5d3723e54b0 Mon Sep 17 00:00:00 2001 From: bd Date: Mon, 24 Feb 2025 12:46:43 -0500 Subject: initial commit --- src/rv.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/rv.cc (limited to 'src/rv.cc') diff --git a/src/rv.cc b/src/rv.cc new file mode 100644 index 0000000..02d95e2 --- /dev/null +++ b/src/rv.cc @@ -0,0 +1,33 @@ +#include +#include + +int main() { + Py_Initialize(); + PyRun_SimpleString("import sys; sys.path.append('src/')"); + PyObject *pName = PyUnicode_DecodeFSDefault("repl.repl"); + PyObject *pModule = PyImport_Import(pName); + Py_DECREF(pName); + + if (pModule != nullptr) { + PyObject *pFunc = PyObject_GetAttrString(pModule, "start"); + if (pFunc && PyCallable_Check(pFunc)) { + PyObject *pArgs = PyTuple_Pack(1, PyUnicode_FromString("World")); + PyObject *pValue = PyObject_CallObject(pFunc, pArgs); + Py_DECREF(pArgs); + if (pValue != nullptr) { + std::cout << PyUnicode_AsUTF8(pValue) << std::endl; + Py_DECREF(pValue); + } else { + PyErr_Print(); + std::cerr << "Call failed" << std::endl; + } + Py_DECREF(pFunc); + } + Py_DECREF(pModule); + } else { + PyErr_Print(); + std::cerr << "Failed to load \"hello\"" << std::endl; + } + Py_Finalize(); + return 0; +} -- cgit v1.2.3