我在模仿另一个文件中的用法的特定行上收到错误。
PyObject *pyCharGetHeight(PyChar *self, void *closure) {
CHAR_DATA *ch = PyChar_AsChar((PyObject *)self);
PyObject *height = NULL;
if(ch != NULL) height = Py_BuildValue("s", charGetHeight(ch));
return height;
}
PyChar_addGetSetter("height", pyCharGetHeight, NULL, "Returns character's height");
正在返回以下错误, PyChar_addGetSetter... 行
错误:预期的声明说明符或字符串常量之前的â...â
我正在使用以下包括:
#include <Python.h>
#include "../scripts/pychar.h"
并且 pychar.h 确实将 PyChar_addGetSetter() 定义为此处的原型:
void PyChar_addGetSetter(const char *name, void *g, void *s, const char *doc);
该函数在../scripts/pychar.c中编写如下:
void PyChar_addGetSetter(const char *name, void *g, void *s, const char *doc) {
// make sure our list of get/setters is created
if(pychar_getsetters == NULL) pychar_getsetters = newList();
// make the GetSetter def
PyGetSetDef *def = calloc(1, sizeof(PyGetSetDef));
def->name = strdup(name);
def->get = (getter)g;
def->set = (setter)s;
def->doc = (doc ? strdup(doc) : NULL);
def->closure = NULL;
listPut(pychar_getsetters, def);
}
似乎无法识别结构或类型,我在猜测我的功能。