From 761dd04914d0bc92fc26bcf9654f94f6be6de74f Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Tue, 25 Jun 2024 11:06:47 -0700 Subject: [PATCH] Added Python functions lf.package_directory() and lf.source_director() --- python/include/pythontarget.h | 16 ++++++++++++++++ python/lib/pythontarget.c | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/python/include/pythontarget.h b/python/include/pythontarget.h index effbe0344..a828e0689 100644 --- a/python/include/pythontarget.h +++ b/python/include/pythontarget.h @@ -102,6 +102,22 @@ PyObject* py_schedule_copy(PyObject* self, PyObject* args); */ PyObject* py_request_stop(PyObject* self, PyObject* args); +/** + * @brief Return the source directory path (where the main .lf file is) as a string. + * @param self The lf object. + * @param args Empty. + * @return PyObject* A Python string. + */ +PyObject* py_source_directory(PyObject* self, PyObject* args); + +/** + * @brief Return the root project directory path as a string. + * @param self The lf object. + * @param args Empty. + * @return PyObject* A Python string. + */ +PyObject* py_package_directory(PyObject* self, PyObject* args); + ////////////////////////////////////////////////////////////// ///////////// Main function callable from Python code PyObject* py_main(PyObject* self, PyObject* args); diff --git a/python/lib/pythontarget.c b/python/lib/pythontarget.c index a485efaf5..3b1265678 100644 --- a/python/lib/pythontarget.c +++ b/python/lib/pythontarget.c @@ -162,6 +162,14 @@ PyObject* py_request_stop(PyObject* self, PyObject* args) { return Py_None; } +PyObject* py_source_directory(PyObject* self, PyObject* args) { + return PyUnicode_DecodeFSDefault(LF_SOURCE_DIRECTORY); +} + +PyObject* py_package_directory(PyObject* self, PyObject* args) { + return PyUnicode_DecodeFSDefault(LF_PACKAGE_DIRECTORY); +} + /** * Parse Python's 'argv' (from sys.argv()) into a pair of C-style * 'argc' (the size of command-line parameters array) @@ -304,6 +312,8 @@ static PyMethodDef GEN_NAME(MODULE_NAME, _methods)[] = {{"start", py_main, METH_ {"tag", py_lf_tag, METH_NOARGS, NULL}, {"tag_compare", py_tag_compare, METH_VARARGS, NULL}, {"request_stop", py_request_stop, METH_NOARGS, "Request stop"}, + {"source_directory", py_source_directory, METH_NOARGS, "Source directory path for .lf file"}, + {"package_directory", py_package_directory, METH_NOARGS, "Root package directory path"}, {NULL, NULL, 0, NULL}}; /**