1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #include "python_const.h"
-
- PyModuleDef rpnconstmodule = {
- PyModuleDef_HEAD_INIT,
- "pyrpn.const",
- "librarie's constants",
- -1, // module size
- NULL, // methods
- NULL,
- NULL,
- NULL
- };
-
- int Py_rpnconst_add(PyObject* mod, const char* name, int value)
- {
- PyObject *val;
- val = Py_BuildValue("i", value);
- Py_INCREF(val);
- if(PyModule_AddObject(mod, name, val) < 0)
- {
- Py_DECREF(val);
- return -1;
- }
- return 0;
- }
-
- PyObject *Py_rpnconst_init(void)
- {
- PyObject *mod;
- mod = PyModule_Create(&rpnconstmodule);
- if(mod == NULL) { return NULL; }
-
- if(Py_rpnconst_add(mod, "POS_LINEAR", RPN_IF_POSITION_LINEAR) ||
- Py_rpnconst_add(mod, "POS_XY", RPN_IF_POSITION_XY) ||
- Py_rpnconst_add(mod, "POS_XDIM", RPN_IF_POSITION_XDIM) ||
- Py_rpnconst_add(mod, "RESULT_BOOL", RPN_IF_RES_BOOL) ||
- Py_rpnconst_add(mod, "RESULT_CONST", RPN_IF_RES_CONST) ||
- Py_rpnconst_add(mod, "RESULT_CONST_RGBA", RPN_IF_RES_CONST_RGBA) ||
- Py_rpnconst_add(mod, "RESULT_COUNT", RPN_IF_RES_COUNT) ||
- Py_rpnconst_add(mod, "RESULT_XFUN", RPN_IF_RES_XFUN) ||
- Py_rpnconst_add(mod, "RESULT_RGB", RPN_IF_RES_RGB) ||
- Py_rpnconst_add(mod, "RESULT_RGBA", RPN_IF_RES_RGBA))
- {
- Py_DECREF(mod);
- return NULL;
- }
- return mod;
- }
-
|