how to make a custom python object?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • elsejj

    how to make a custom python object?

    i want make a new object named 'vector' to my python release,
    the 'vector' is most like a 'list', but have some number operatioins
    such as add, sub, ect. i create the head file vectorobject.h based
    on listobject.h, i create the src file vectorobject.c based on
    listobject.c and intobject.c.
    1 i had create PyVectorObject like this
    typedef struct {
    PyObject_VAR_HE AD
    double* ob_item;
    } PyVectorObject;

    2 i had create the PyVector_Type like this
    PyAPI_DATA(PyTy peObject);
    and initialize it in vectorobject.c like
    PyTypeObject PyVector_Type = {
    PyObject_HEAD_I NIT(&PyType_Typ e)
    0,
    "vector",
    sizeof(PyVector Object),
    0,
    (destructor)vec tor_dealloc, /* tp_dealloc */
    (printfunc)vect or_print, /* tp_print */
    0, /* tp_getattr
    */
    0, /* tp_setattr
    */
    0, /* tp_compare */
    0, /* tp_repr */
    &vector_as_numb er, /*
    tp_as_number */
    0, /*
    tp_as_sequence */
    0, /*
    tp_as_mapping */
    ....

    but it dosen't works, i can't declare the object and used it, who
    can tell me how to do, thanks very much.


Working...