aboutsummaryrefslogtreecommitdiff
path: root/lib/base/nconfig.cpp
blob: 562b3503c838d5704e12179611ef7598c31dfb4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <lib/base/nconfig.h>
#include <Python.h>

PyObject *ePythonConfigQuery::m_queryFunc;

void ePythonConfigQuery::setQueryFunc(PyObject *queryFunc)
{
	if (m_queryFunc)
		Py_DECREF(m_queryFunc);
	m_queryFunc = queryFunc;
	if (m_queryFunc)
		Py_INCREF(m_queryFunc);
}

RESULT ePythonConfigQuery::getConfigValue(const char *key, std::string &value)
{
	if (key && PyCallable_Check(m_queryFunc))
	{
		PyObject *pArgs = PyTuple_New(1);
		PyTuple_SET_ITEM(pArgs, 0, PyString_FromString(key));
		PyObject *pRet = PyObject_CallObject(m_queryFunc, pArgs);
		Py_DECREF(pArgs);
		if (pRet)
		{
			if (PyString_Check(pRet))
			{
				value.assign(PyString_AS_STRING(pRet));
				return 0;
			}
			Py_DECREF(pRet);
		}
	}
	return -1;
}