diff --git a/src/engine/builtins.c b/src/engine/builtins.c index 65930fe77..d8014be95 100644 --- a/src/engine/builtins.c +++ b/src/engine/builtins.c @@ -1744,6 +1744,30 @@ bjam_define_action(PyObject* self, PyObject *args) return Py_None; } +/* Returns the value of a variable in root Jam module. */ +PyObject* +bjam_variable(PyObject* self, PyObject* args) +{ + char *name; + LIST* value; + PyObject *result; + int i; + + if (!PyArg_ParseTuple(args, "s", &name)) + return NULL; + + enter_module(root_module()); + value = var_get(name); + exit_module(root_module()); + + result = PyList_New(list_length(value)); + for (i = 0; value; value = list_next(value), ++i) + PyList_SetItem(result, i, PyString_FromString(value->string)); + + return result; +} + + #endif #ifdef HAVE_POPEN diff --git a/src/engine/jam.c b/src/engine/jam.c index 33c138e1a..1533bfe57 100644 --- a/src/engine/jam.c +++ b/src/engine/jam.c @@ -209,6 +209,9 @@ static void run_unit_tests() extern PyObject* bjam_define_action(PyObject* self, PyObject* args); + + extern PyObject* + bjam_variable(PyObject* self, PyObject* args); #endif int main( int argc, char **argv, char **arg_environ ) @@ -344,6 +347,8 @@ int main( int argc, char **argv, char **arg_environ ) "Imports Python callable to bjam."}, {"define_action", bjam_define_action, METH_VARARGS, "Defines a command line action."}, + {"variable", bjam_variable, METH_VARARGS, + "Obtains a variable from bjam's global module."}, {NULL, NULL, 0, NULL} };