KVIrc  4.9.2
DeveloperAPIs
kvircmodule.h
Go to the documentation of this file.
1 #ifndef Py_KVIRCMODULE_H
2 #define Py_KVIRCMODULE_H
3 //=============================================================================
4 //
5 // File : kvircmodule.h
6 // Creation date : Wed Nov 19 19:11:29 2008 GMT by Elvio Basello
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2008 Elvio Basello (hellvis69 at netsons dot org)
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
36 #include "kvi_settings.h"
37 
38 #ifdef COMPILE_PYTHON_SUPPORT
39 
40 #include <Python.h>
41 
42 // python included like to pollute the global namespace, let's #undef some beef
43 #undef isspace
44 #undef isupper
45 #undef islower
46 #undef isalpha
47 #undef isalnum
48 #undef toupper
49 #undef tolower
50 
51 // Prototype
52 PyMODINIT_FUNC python_init();
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 #ifndef KVIRC_MODULE
58 // This section is used in modules that use kvircmodule's API
59 static void ** PyKVIrc_API;
60 
61 #define PyKVIrc_echo \
62  (*(int (*)(const char * pcCmd))PyKVIrc_API[0])
63 #define PyKVIrc_say \
64  (*(int (*)(const char * pcCmd))PyKVIrc_API[1])
65 #define PyKVIrc_warning \
66  (*(int (*)(const char * pcCmd))PyKVIrc_API[2])
67 #define PyKVIrc_getLocal \
68  (*(int (*)(const char * pcCmd))PyKVIrc_API[3])
69 #define PyKVIrc_setLocal \
70  (*(int (*)(const char * pcCmd))PyKVIrc_API[4])
71 #define PyKVIrc_getGlobal \
72  (*(int (*)(const char * pcCmd))PyKVIrc_API[5])
73 #define PyKVIrc_setGlobal \
74  (*(int (*)(const char * pcCmd))PyKVIrc_API[6])
75 #define PyKVIrc_eval \
76  (*(int (*)(const char * pcCmd))PyKVIrc_API[7])
77 #define PyKVIrc_internalWarning \
78  (*(int (*)(const char * pcCmd))PyKVIrc_API[8])
79 #define PyKVIrc_error \
80  (*(int (*)(const char * pcCmd))PyKVIrc_API[9])
81 
87 inline static int import_kvirc()
88 {
89  PyObject * pModule = PyImport_ImportModule("kvirc");
90  if(pModule)
91  {
92  PyObject * pC_API_Object = PyObject_GetAttrString(pModule, "_C_API");
93 
94  if(!pC_API_Object)
95  return -1;
96 
97  if(PyCObject_Check(pC_API_Object))
98  PyKVIrc_API = (void **)PyCObject_AsVoidPtr(pC_API_Object);
99 
100  Py_DECREF(pC_API_Object);
101  }
102  return 0;
103 }
104 #endif // KVIRC_MODULE
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif // COMPILE_PYTHON_SUPPORT
111 
112 #endif // Py_KVIRCMODULE_H
This file contains compile time settings.