Crossfire Server, Branches 1.12  R18729
cfpython.h
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* CFPython - A Python module for Crossfire RPG. */
3 /* Version: 2.0beta8 (also known as "Alexander") */
4 /* Contact: yann.chachkoff@myrealbox.com */
5 /*****************************************************************************/
6 /* That code is placed under the GNU General Public Licence (GPL) */
7 /* (C)2001-2005 by Chachkoff Yann (Feel free to deliver your complaints) */
8 /*****************************************************************************/
9 /* CrossFire, A Multiplayer game for X-windows */
10 /* */
11 /* Copyright (C) 2000 Mark Wedel */
12 /* Copyright (C) 1992 Frank Tore Johansen */
13 /* */
14 /* This program is free software; you can redistribute it and/or modify */
15 /* it under the terms of the GNU General Public License as published by */
16 /* the Free Software Foundation; either version 2 of the License, or */
17 /* (at your option) any later version. */
18 /* */
19 /* This program is distributed in the hope that it will be useful, */
20 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
21 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
22 /* GNU General Public License for more details. */
23 /* */
24 /* You should have received a copy of the GNU General Public License */
25 /* along with this program; if not, write to the Free Software */
26 /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 /* */
28 /*****************************************************************************/
29 #ifndef PLUGIN_PYTHON_H
30 #define PLUGIN_PYTHON_H
31 
32 /* First the required header files - only the CF module interface and Python */
33 #ifdef WIN32
34  #ifdef _DEBUG
35  #undef _DEBUG
36  #include <Python.h>
37  #define _DEBUG
38  #else
39  #include <Python.h>
40  #endif
41 #else /* WIN32 */
42  #include <Python.h>
43 #endif
44 
45 /* This is for allowing both python 3 and python 2.
46  * We also use some warnings and such with python 2.6 (and later 2.x).
47  */
48 #if PY_MAJOR_VERSION >= 3
49 # define IS_PY3K
50 #else /* Python 2.x */
51 # if PY_MINOR_VERSION >= 6 /* 2.6 or later */
52 # define IS_PY26
53 # else
54 # define IS_PY_LEGACY /* Pre-2.6 lack forward compat. changes for Py3 */
55 # endif
56 # if PY_MINOR_VERSION >= 5 /* PyNumberMethods changed in 2.5 */
57 # define IS_PY25
58 # endif
59 #endif
60 
61 /* Python 2.5 or older doesn't define these. */
62 #ifndef Py_SIZE
63 # define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
64 #endif
65 #ifndef Py_TYPE
66 # define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
67 #endif
68 
69 /* Python 2.6 and later use PyObject_HashNotImplemented to indicate no support
70  * for hash.
71  */
72 #ifdef IS_PY_LEGACY
73 # define PyObject_HashNotImplemented NULL
74 #endif
75 
76 /* Handle Bytes vs. String */
77 #ifdef IS_PY3K
78 # define CF_IS_PYSTR(cfpy_obj) (PyUnicode_Check(cfpy_obj))
79 #else
80 # define CF_IS_PYSTR(cfpy_obj) (PyString_Check(cfpy_obj) || PyUnicode_Check(cfpy_obj))
81 #endif
82 
83 /* Python can define HAVE_GETTIMEOFDAY, but we have our own later on. */
84 #ifdef HAVE_GETTIMEOFDAY
85 #undef HAVE_GETTIMEOFDAY
86 #endif
87 
88 /* include compile.h from python. Python.h doesn't pull it in with versions
89  * 2.3 and older, and it does have protection from double-imports.
90  */
91 #include <compile.h>
92 #include <plugin.h>
93 
94 #undef MODULEAPI
95 #ifdef WIN32
96 #ifdef PYTHON_PLUGIN_EXPORTS
97 #define MODULEAPI __declspec(dllexport)
98 #else
99 #define MODULEAPI __declspec(dllimport)
100 #endif
101 
102 #else
103 #define MODULEAPI
104 #endif
105 
106 #define PLUGIN_NAME "Python"
107 #define PLUGIN_VERSION "CFPython Plugin 2.0a13 (Fido)"
108 
109 #include <plugin_common.h>
110 #include <cfpython_object.h>
111 #include <cfpython_map.h>
112 #include <cfpython_archetype.h>
113 #include <cfpython_party.h>
114 #include <cfpython_region.h>
115 
116 typedef struct _cfpcontext {
117  struct _cfpcontext *down;
118  PyObject *who;
119  PyObject *activator;
120  PyObject *third;
121  PyObject *event;
122  char message[1024];
123  int fix;
125  char script[1024];
126  char options[1024];
128  int parms[5];
129 } CFPContext;
130 
131 extern f_plug_api gethook;
132 
133 extern CFPContext *context_stack;
134 
136 
137 /* This structure is used to define one python-implemented crossfire command.*/
138 typedef struct PythonCmdStruct {
139  char *name; /* The name of the command, as known in the game. */
140  char *script; /* The name of the script file to bind. */
141  double speed; /* The speed of the command execution. */
142 } PythonCmd;
143 
144 /* This plugin allows up to 1024 custom commands. */
145 #define NR_CUSTOM_CMD 1024
146 #include <cfpython_proto.h>
147 
148 #endif /* PLUGIN_PYTHON_H */
CFPContext * context_stack
Definition: cfpython.c:184
PyObject * third
Definition: cfpython.h:120
int event_code
Definition: cfpython.h:124
PyObject * activator
Definition: cfpython.h:119
char options[1024]
Definition: cfpython.h:126
void *(* f_plug_api)(int *type,...)
Definition: plugin.h:121
char message[1024]
Definition: cfpython.h:122
f_plug_api gethook
Definition: cfnewspaper.c:38
char script[1024]
Definition: cfpython.h:125
double speed
Definition: cfpython.h:141
PyObject * event
Definition: cfpython.h:121
char * script
Definition: cfpython.h:140
PyObject * who
Definition: cfpython.h:118
int parms[5]
Definition: cfpython.h:128
struct _cfpcontext * down
Definition: cfpython.h:117
int returnvalue
Definition: cfpython.h:127
struct _cfpcontext CFPContext
struct PythonCmdStruct PythonCmd
CFPContext * current_context
Definition: cfpython.c:186