aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py/source/register.cpp
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2002-10-22 23:16:30 +0000
committerThomas Grill <xovo@users.sourceforge.net>2002-10-22 23:16:30 +0000
commitc2645dc4003b1391aba9b387a79a66cff1e63d3e (patch)
tree1ea6dccb8011a8ff64efb7c2ecf9a22caad860b3 /externals/grill/py/source/register.cpp
parentd62e56f4df9594f72ce501f5e19c974fd18e7295 (diff)
This commit was generated by cvs2svn to compensate for changes in r189,
which included commits to RCS files with non-trunk default branches. svn path=/trunk/; revision=190
Diffstat (limited to 'externals/grill/py/source/register.cpp')
-rw-r--r--externals/grill/py/source/register.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/externals/grill/py/source/register.cpp b/externals/grill/py/source/register.cpp
new file mode 100644
index 00000000..63a9f952
--- /dev/null
+++ b/externals/grill/py/source/register.cpp
@@ -0,0 +1,86 @@
+/*
+
+py/pyext - python external object for PD and MaxMSP
+
+Copyright (c) 2002 Thomas Grill (xovo@gmx.net)
+For information on usage and redistribution, and for a DISCLAIMER OF ALL
+WARRANTIES, see the file, "license.txt," in this distribution.
+
+*/
+
+#include "main.h"
+
+
+V py::Register(const C *regnm)
+{
+ if(module) {
+ // add this to module registry
+
+ PyObject *reg = PyDict_GetItemString(dict,(C *)regnm); // borrowed!!!
+ PyObject *add = Py_BuildValue("[i]",(long)this);
+ if(!reg || !PyList_Check(reg)) {
+ if(PyDict_SetItemString(dict,(C *)regnm,add)) {
+ post("%s - Could not set registry",thisName());
+ }
+ // Py_XDECREF(reg);
+ }
+ else {
+ PySequence_InPlaceConcat(reg,add);
+ }
+ }
+
+}
+
+V py::Unregister(const C *regnm)
+{
+ if(module) {
+ // remove this from module registry
+
+ PyObject *reg = PyDict_GetItemString(dict,(C *)regnm); // borrowed!!!
+ PyObject *add = Py_BuildValue("i",(int)this);
+ if(!reg || !PySequence_Check(reg))
+ post("%s - Registry not found!?",thisName());
+ else {
+ I ix = PySequence_Index(reg,add);
+ if(ix < 0) {
+ post("%s - This object not found in registry?!",thisName());
+ }
+ else {
+ PySequence_DelItem(reg,ix);
+ }
+ }
+ Py_DECREF(add);
+ }
+
+}
+
+V py::Reregister(const C *regnm)
+{
+ if(module) {
+ // remove this from module registry
+
+ PyObject *reg = PyDict_GetItemString(dict,(C *)regnm); // borrowed!!!
+
+ if(!reg || !PySequence_Check(reg))
+ post("%s - Registry not found!?",thisName());
+ else {
+ I cnt = PySequence_Size(reg);
+ for(I i = 0; i < cnt; ++i) {
+ PyObject *it = PySequence_GetItem(reg,i); // borrowed!!
+ if(!it || !PyInt_Check(it)) {
+ post("%s - Corrupt registry?!",thisName());
+ }
+ else {
+ py *th = (py *)PyInt_AsLong(it);
+ th->module = module;
+ th->dict = dict;
+ th->Reload();
+ }
+ }
+ }
+ }
+
+}
+
+
+