Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. typedef struct {
  2.     PyObject_HEAD
  3.     int my_int;
  4.     double my_double;
  5.     PyObject *my_pyobject;
  6. } cvarobject;
  7.  
  8. static PyTypeObject cvar_type;
  9.  
  10.  // If you want to make this non-static, make sure to avoid name clashes.
  11. static cvarobject globals = {
  12.     PyObject_HEAD_INIT(&cvar_type)
  13. };
  14.  
  15. static PyMemberDef cvar_members[] = {
  16.     // see https://docs.python.org/3/c-api/structures.html#c.PyMethodDef
  17.     {"my_int", T_INT, offsetof(cvarobject, my_int), 0},
  18.     {"my_double", T_DOUBLE, offsetof(cvarobject, my_double), 0},
  19.     {"my_pyobject", T_OBJECT_EX, offsetof(cvarobject, my_pyobject), 0}
  20. }
  21.  
  22. static PyTypeObject cvar_type {
  23.     PyObject_HEAD_INIT(NULL)
  24.     "mymodule.cvar_type",      /* tp_name */
  25.     sizeof(cvarobject),        /* tp_basicsize */
  26.     // Designated initializer, to skip all the stuff in between
  27.     // that should just be zeroed.
  28.     .tp_members=cvar_members
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement