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
113
114
115
116
117
118
|
#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 opinion) 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. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, 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>
// Prototype
PyMODINIT_FUNC python_init();
#ifdef __cplusplus
extern "C" {
#endif
// Total number of C API pointers
#define PyKVIrc_API_NUM 10
#ifdef KVIRC_MODULE
// This section is used when compiling kvircmodule.cpp
static PyObject * PyKVIrc_echo(PyObject * pSelf, PyObject * pArgs);
static PyObject * PyKVIrc_say(PyObject * pSelf, PyObject * pArgs);
static PyObject * PyKVIrc_warning(PyObject * pSelf, PyObject * pArgs);
static PyObject * PyKVIrc_getLocal(PyObject * pSelf, PyObject * pArgs);
static PyObject * PyKVIrc_setLocal(PyObject * pSelf, PyObject * pArgs);
static PyObject * PyKVIrc_getGlobal(PyObject * pSelf, PyObject * pArgs);
static PyObject * PyKVIrc_setGlobal(PyObject * pSelf, PyObject * pArgs);
static PyObject * PyKVIrc_eval(PyObject * pSelf, PyObject * pArgs);
static PyObject * PyKVIrc_internalWarning(PyObject * pSelf, PyObject * pArgs);
static PyObject * PyKVIrc_error(PyObject * pSelf, PyObject * pArgs);
#else
// 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
*/
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
|