Skip to content

Commit

Permalink
Added Python functions lf.package_directory() and lf.source_director()
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardalee committed Jun 25, 2024
1 parent eb48bae commit 761dd04
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions python/include/pythontarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions python/lib/pythontarget.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}};

/**
Expand Down

0 comments on commit 761dd04

Please sign in to comment.