aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/pythoncore/kvircmodule.h
blob: 53376d57754d93da0cf5487942b567de01ea8882 (about) (plain) (blame)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef Py_KVIRCMODULE_H
#define Py_KVIRCMODULE_H
//=============================================================================
//
//   File : kvircmodule.h
//   Creation date : Wed Nov 19 19:11:29 2008 GMT by Elvio Basello
//
//   This file is part of the KVIrc IRC client distribution
//   Copyright (C) 2008 Elvio Basello (hellvis69 at netsons dot org)
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your option) any later version.
//
//   This program is distributed in the HOPE that it will be USEFUL,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================

/**
* \file kvircmodule.h
* \author Elvio Basello
* \brief KVIrc module for Python
*
* This python module defines some functions to interact with KVIrc and run its
* builtin functions. It's useful when writing Python scripts inside KVIrc.
*/

#include "kvi_settings.h"

#ifdef COMPILE_PYTHON_SUPPORT

#include <Python.h>

// python included like to pollute the global namespace, let's #undef some beef
#undef isspace
#undef isupper
#undef islower
#undef isalpha
#undef isalnum
#undef toupper
#undef tolower

// Prototype
PyMODINIT_FUNC python_init();

#ifdef __cplusplus
extern "C" {
#endif
#ifndef KVIRC_MODULE
// This section is used in modules that use kvircmodule's API
static void ** PyKVIrc_API;

#define PyKVIrc_echo \
	(*(int (*)(const char * pcCmd))PyKVIrc_API[0])
#define PyKVIrc_say \
	(*(int (*)(const char * pcCmd))PyKVIrc_API[1])
#define PyKVIrc_warning \
	(*(int (*)(const char * pcCmd))PyKVIrc_API[2])
#define PyKVIrc_getLocal \
	(*(int (*)(const char * pcCmd))PyKVIrc_API[3])
#define PyKVIrc_setLocal \
	(*(int (*)(const char * pcCmd))PyKVIrc_API[4])
#define PyKVIrc_getGlobal \
	(*(int (*)(const char * pcCmd))PyKVIrc_API[5])
#define PyKVIrc_setGlobal \
	(*(int (*)(const char * pcCmd))PyKVIrc_API[6])
#define PyKVIrc_eval \
	(*(int (*)(const char * pcCmd))PyKVIrc_API[7])
#define PyKVIrc_internalWarning \
	(*(int (*)(const char * pcCmd))PyKVIrc_API[8])
#define PyKVIrc_error \
	(*(int (*)(const char * pcCmd))PyKVIrc_API[9])
/**
		* \brief Returns 0 on success, -1 otherwise
		*
		* In case on unsuccess, it sets the exception
		* \return int
		*/
inline static int import_kvirc()
{
	PyObject * pModule = PyImport_ImportModule("kvirc");
	if(pModule)
	{
		PyObject * pC_API_Object = PyObject_GetAttrString(pModule, "_C_API");

		if(!pC_API_Object)
			return -1;

		if(PyCObject_Check(pC_API_Object))
			PyKVIrc_API = (void **)PyCObject_AsVoidPtr(pC_API_Object);

		Py_DECREF(pC_API_Object);
	}
	return 0;
}
#endif // KVIRC_MODULE

#ifdef __cplusplus
}
#endif

#endif // COMPILE_PYTHON_SUPPORT

#endif // Py_KVIRCMODULE_H