Esempio n. 1
0
PYTHON_INIT_DEFINITION(ptPlayer, args, keywords)
{
    // we have two sets of arguments we can use, hence the generic PyObject* pointers
    // argument set 1: pyKey, string, uint32_t, float
    // argument set 2: string, uint32_t
    PyObject* firstObj = NULL; // can be a pyKey or a string
    PyObject* secondObj = NULL; // can be a string or a uint32_t
    PyObject* thirdObj = NULL; // uint32_t
    PyObject* fourthObj = NULL; // float
    if (!PyArg_ParseTuple(args, "OO|OO", &firstObj, &secondObj, &thirdObj, &fourthObj))
    {
        PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
        PYTHON_RETURN_INIT_ERROR;
    }

    plKey key;
    plString name;
    uint32_t pid = -1;
    float distSeq = -1;

    if (pyKey::Check(firstObj))
    {
        if (!(PyString_CheckEx(secondObj) && PyNumber_Check(thirdObj) && PyFloat_Check(fourthObj)))
        {
            PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
            PYTHON_RETURN_INIT_ERROR;
        }

        key = pyKey::ConvertFrom(firstObj)->getKey();
        name = PyString_AsStringEx(secondObj);
        pid = PyNumber_AsSsize_t(thirdObj, NULL);
        distSeq = (float)PyFloat_AsDouble(fourthObj);
    } else if (PyString_CheckEx(firstObj)) {
        name = PyString_AsStringEx(firstObj);
        if (!PyNumber_Check(secondObj) || thirdObj  || fourthObj)
        {
            PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
            PYTHON_RETURN_INIT_ERROR;
        }

        pid = PyNumber_AsSsize_t(secondObj, NULL);
    } else {
        PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
        PYTHON_RETURN_INIT_ERROR;
    }

    self->fThis->Init(key, name.c_str(), pid, distSeq);
    PYTHON_RETURN_INIT_OK;
}
Esempio n. 2
0
PYTHON_METHOD_DEFINITION(ptStatusLog, write, args)
{
    PyObject* text;
    PyObject* colorObj = NULL;
    if (!PyArg_ParseTuple(args, "O|O", &text, &colorObj))
    {
        PyErr_SetString(PyExc_TypeError, "write expects a string and an optional ptColor");
        PYTHON_RETURN_ERROR;
    }
    if (!PyString_CheckEx(text))
    {
        PyErr_SetString(PyExc_TypeError, "write expects a string and an optional ptColor");
        PYTHON_RETURN_ERROR;
    }
    if (colorObj)
    {
        if (!pyColor::Check(colorObj))
        {
            PyErr_SetString(PyExc_TypeError, "write expects a string and an optional ptColor");
            PYTHON_RETURN_ERROR;
        }
        pyColor* color = pyColor::ConvertFrom(colorObj);
        PYTHON_RETURN_BOOL(self->fThis->WriteColor(PyString_AsStringEx(text), *color));
    }
    PYTHON_RETURN_BOOL(self->fThis->Write(PyString_AsStringEx(text)));
}
PYTHON_METHOD_DEFINITION(ptVaultMarkerGameNode, setMarkers, args)
{
    PyObject* main_seq;
    const char* errmsg = "setMarkers expects a sequence of markers (tuple of int, string, ptPoint3, string)";
    if (!PyArg_ParseTuple(args, "O", &main_seq)) {
        PyErr_SetString(PyExc_TypeError, errmsg);
        PYTHON_RETURN_ERROR;
    }
    if (!PySequence_Check(main_seq)) {
        PyErr_SetString(PyExc_TypeError, errmsg);
        PYTHON_RETURN_ERROR;
    }

    std::vector<VaultMarker> collector;
    collector.reserve(PySequence_Size(main_seq));
    for (Py_ssize_t i = 0; i < PySequence_Size(main_seq); ++i) {
        PyObject* marker_seq = PySequence_GetItem(main_seq, i);
        if (!PySequence_Check(marker_seq) || PySequence_Size(marker_seq) != 4) {
            PyErr_SetString(PyExc_TypeError, errmsg);
            PYTHON_RETURN_ERROR;
        }

        PyObject* id   = PySequence_GetItem(marker_seq, 0);
        PyObject* age  = PySequence_GetItem(marker_seq, 1);
        PyObject* pos  = PySequence_GetItem(marker_seq, 2);
        PyObject* desc = PySequence_GetItem(marker_seq, 3);
        if (!(PyInt_Check(id) && PyString_CheckEx(age) && pyPoint3::Check(pos) && PyString_CheckEx(desc))) {
            PyErr_SetString(PyExc_TypeError, errmsg);
            PYTHON_RETURN_ERROR;
        }

        VaultMarker marker;
        marker.id = PyLong_AsUnsignedLong(id);
        marker.age = PyString_AsStringEx(age);
        marker.pos = pyPoint3::ConvertFrom(pos)->fPoint;
        marker.description = PyString_AsStringEx(desc);
        collector.push_back(marker);
    }

    self->fThis->SetMarkers(collector);
    PYTHON_RETURN_NONE;
}
PYTHON_METHOD_DEFINITION(ptVaultMarkerGameNode, setGameName, args)
{
    PyObject* name;
    if (!PyArg_ParseTuple(args, "O", &name) || !PyString_CheckEx(name))
    {
        PyErr_SetString(PyExc_TypeError, "setGameName expects a string");
        PYTHON_RETURN_ERROR;
    }
    self->fThis->SetGameName(PyString_AsStringEx(name));
    PYTHON_RETURN_NONE;
}
Esempio n. 5
0
PYTHON_METHOD_DEFINITION(ptStatusLog, open, args)
{
    PyObject* logName;
    unsigned long numLines, flags;
    if (!PyArg_ParseTuple(args, "Oll", &logName, &numLines, &flags))
    {
        PyErr_SetString(PyExc_TypeError, "open expects a string and two unsigned longs");
        PYTHON_RETURN_ERROR;
    }
    if (!PyString_CheckEx(logName))
    {
        PyErr_SetString(PyExc_TypeError, "open expects a string and two unsigned longs");
        PYTHON_RETURN_ERROR;
    }
    PYTHON_RETURN_BOOL(self->fThis->Open(PyString_AsStringEx(logName), numLines, flags));
}