diff options
| author | Dana Jansens <danakj@orodu.net> | 2003-03-16 23:15:20 +0000 |
|---|---|---|
| committer | Dana Jansens <danakj@orodu.net> | 2003-03-16 23:15:20 +0000 |
| commit | 7f590e53607ef1592d65a425b9cdcaa181912465 (patch) | |
| tree | bd0baf4b5563845bd8b2339aefd354e4dcd11527 /openbox/configwrap.c | |
| parent | 74c683ee5fb232d7fe9f517b21ffd9ee50872dce (diff) | |
pointer's variables are config vars
Diffstat (limited to 'openbox/configwrap.c')
| -rw-r--r-- | openbox/configwrap.c | 80 |
1 files changed, 80 insertions, 0 deletions
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 <Python.h> +#include <glib.h> + +/* 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); +} |
