From 7f590e53607ef1592d65a425b9cdcaa181912465 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Sun, 16 Mar 2003 23:15:20 +0000 Subject: pointer's variables are config vars --- openbox/configwrap.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 openbox/configwrap.c (limited to 'openbox/configwrap.c') diff --git a/openbox/configwrap.c b/openbox/configwrap.c new file mode 100644 index 00000000..3afa5c4c --- /dev/null +++ b/openbox/configwrap.c @@ -0,0 +1,80 @@ +#include +#include + +/* This simply wraps the config.py module so that it can be accessed from the + C code. +*/ + +static PyObject *add, *get, *set, *reset; + +void configwrap_startup() +{ + PyObject *c, *cdict; + + /* get the ob module/dict */ + c = PyImport_ImportModule("config"); /* new */ + g_assert(c != NULL); + cdict = PyModule_GetDict(c); /* borrowed */ + g_assert(cdict != NULL); + + /* get the functions */ + add = PyDict_GetItemString(cdict, "add"); + g_assert(add != NULL); + get = PyDict_GetItemString(cdict, "get"); + g_assert(get != NULL); + set = PyDict_GetItemString(cdict, "set"); + g_assert(set != NULL); + reset = PyDict_GetItemString(cdict, "reset"); + g_assert(reset != NULL); + + Py_DECREF(c); +} + +void configwrap_shutdown() +{ + Py_DECREF(get); + Py_DECREF(set); + Py_DECREF(reset); + Py_DECREF(add); +} + +void configwrap_add_int(char *modname, char *varname, char *friendname, + char *description, int defvalue) +{ + PyObject *r; + + r= PyObject_CallFunction(add, "sssssi", modname, varname, + friendname, description, "integer", defvalue); + g_assert(r != NULL); + Py_DECREF(r); +} + +int configwrap_get_int(char *modname, char *varname) +{ + PyObject *r; + int i; + + r = PyObject_CallFunction(get, "ss", modname, varname); + g_assert(r != NULL); + i = PyInt_AsLong(r); + Py_DECREF(r); + return i; +} + +void configwrap_set_int(char *modname, char *varname, int value) +{ + PyObject *r; + + r = PyObject_CallFunction(set, "ssi", modname, varname, value); + g_assert(r != NULL); + Py_DECREF(r); +} + +void configwrap_reset(char *modname, char *varname) +{ + PyObject *r; + + r = PyObject_CallFunction(reset, "ss", modname, varname); + g_assert(r != NULL); + Py_DECREF(r); +} -- cgit v1.2.3