aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py/source
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2004-08-21 04:17:01 +0000
committerThomas Grill <xovo@users.sourceforge.net>2004-08-21 04:17:01 +0000
commite4eff144d6733edd2111e53613904f22cef9a109 (patch)
tree9d3f38dd676e5c791089fbc3ad956cc493f61a02 /externals/grill/py/source
parentba5b1684b1279115b95e274d1854fb14fe49587e (diff)
""
svn path=/trunk/; revision=1965
Diffstat (limited to 'externals/grill/py/source')
-rw-r--r--externals/grill/py/source/main.h2
-rw-r--r--externals/grill/py/source/py.cpp3
-rw-r--r--externals/grill/py/source/pyext.cpp96
-rw-r--r--externals/grill/py/source/pyext.h1
4 files changed, 63 insertions, 39 deletions
diff --git a/externals/grill/py/source/main.h b/externals/grill/py/source/main.h
index 0bbb92d3..bf0ca6cc 100644
--- a/externals/grill/py/source/main.h
+++ b/externals/grill/py/source/main.h
@@ -29,7 +29,7 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#error You need at least flext version 0.4.6
#endif
-#define PY__VERSION "0.1.3"
+#define PY__VERSION "0.1.4pre"
#define PYEXT_MODULE "pyext" // name for module
diff --git a/externals/grill/py/source/py.cpp b/externals/grill/py/source/py.cpp
index 8b14a485..4690fb50 100644
--- a/externals/grill/py/source/py.cpp
+++ b/externals/grill/py/source/py.cpp
@@ -127,9 +127,12 @@ pyobj::pyobj(I argc,const t_atom *argv):
// add current dir to path
AddToPath(GetString(canvas_getcurrentdir()));
#elif FLEXT_SYS == FLEXT_SYS_MAX
+#if FLEXT_OS == FLEXT_OS_WIN
+#else
short path = patcher_myvol(thisCanvas());
path_topathname(path,NULL,dir);
AddToPath(dir);
+#endif
#else
#pragma message("Adding current dir to path is not implemented")
#endif
diff --git a/externals/grill/py/source/pyext.cpp b/externals/grill/py/source/pyext.cpp
index df47beff..7ce0995c 100644
--- a/externals/grill/py/source/pyext.cpp
+++ b/externals/grill/py/source/pyext.cpp
@@ -167,13 +167,27 @@ pyext::pyext(I argc,const t_atom *argv):
if(methname) {
MakeInstance();
- if(inlets < 0 && outlets < 0) {
- // now get number of inlets and outlets
- inlets = 1,outlets = 1;
+ if(pyobj) {
+ if(inlets >= 0) {
+ // set number of inlets
+ PyObject *res = PyInt_FromLong(inlets);
+ int ret = PyObject_SetAttrString(pyobj,"_inlets",res);
+ FLEXT_ASSERT(!ret);
+ }
+ if(outlets >= 0) {
+ // set number of outlets
+ PyObject *res = PyInt_FromLong(outlets);
+ int ret = PyObject_SetAttrString(pyobj,"_outlets",res);
+ FLEXT_ASSERT(!ret);
+ }
- if(pyobj) {
- PyObject *res;
- res = PyObject_GetAttrString(pyobj,"_inlets"); // get ref
+ DoInit(); // call __init__ constructor
+ // __init__ can override the number of inlets and outlets
+
+ if(inlets < 0) {
+ // get number of inlets
+ inlets = 1;
+ PyObject *res = PyObject_GetAttrString(pyobj,"_inlets"); // get ref
if(res) {
if(PyCallable_Check(res)) {
PyObject *fres = PyEval_CallObject(res,NULL);
@@ -186,8 +200,11 @@ pyext::pyext(I argc,const t_atom *argv):
}
else
PyErr_Clear();
-
- res = PyObject_GetAttrString(pyobj,"_outlets"); // get ref
+ }
+ if(outlets < 0) {
+ // get number of outlets
+ outlets = 1;
+ PyObject *res = PyObject_GetAttrString(pyobj,"_outlets"); // get ref
if(res) {
if(PyCallable_Check(res)) {
PyObject *fres = PyEval_CallObject(res,NULL);
@@ -200,13 +217,16 @@ pyext::pyext(I argc,const t_atom *argv):
}
else
PyErr_Clear();
- }
+ }
}
}
- else inlets = outlets = 0;
+ else
+ inlets = outlets = 0;
PY_UNLOCK
+ FLEXT_ASSERT(inlets >= 0 && outlets >= 0);
+
AddInAnything(1+inlets);
AddOutAnything(outlets);
@@ -227,6 +247,33 @@ pyext::~pyext()
PY_UNLOCK
}
+BL pyext::DoInit()
+{
+ // remember the this pointer
+ PyObject *th = PyLong_FromVoidPtr(this);
+ int ret = PyObject_SetAttrString(pyobj,"_this",th); // ref is taken
+
+ // call init now, after _this has been set, which is
+ // important for eventual callbacks from __init__ to c
+ PyObject *pargs = MakePyArgs(NULL,args.Count(),args.Atoms(),-1,true);
+ if(!pargs) PyErr_Print();
+
+ PyObject *init = PyObject_GetAttrString(pyobj,"__init__"); // get ref
+ if(init) {
+ if(PyCallable_Check(init)) {
+ PyObject *res = PyEval_CallObject(init,pargs);
+ if(!res)
+ PyErr_Print();
+ else
+ Py_DECREF(res);
+ }
+ Py_DECREF(init);
+ }
+
+ Py_XDECREF(pargs);
+ return true;
+}
+
BL pyext::MakeInstance()
{
// pyobj should already have been decref'd / cleared before getting here!!
@@ -240,34 +287,7 @@ BL pyext::MakeInstance()
// make instance, but don't call __init__
pyobj = PyInstance_NewRaw(pref,NULL);
- if(pyobj == NULL)
- PyErr_Print();
- else {
- // remember the this pointer
- PyObject *th = PyLong_FromVoidPtr(this);
- int ret = PyObject_SetAttrString(pyobj,"_this",th); // ref is taken
-
- // call init now, after _this has been set, which is
- // important for eventual callbacks from __init__ to c
- PyObject *pargs = MakePyArgs(NULL,args.Count(),args.Atoms(),-1,true);
- if (pargs == NULL)
- PyErr_Print();
-
- PyObject *init;
- init = PyObject_GetAttrString(pyobj,"__init__"); // get ref
- if(init) {
- if(PyCallable_Check(init)) {
- PyObject *res = PyEval_CallObject(init,pargs);
- if(!res)
- PyErr_Print();
- else
- Py_DECREF(res);
- }
- Py_DECREF(init);
- }
-
- Py_XDECREF(pargs);
- }
+ if(!pyobj) PyErr_Print();
}
else
post("%s - Type of \"%s\" is unhandled!",thisName(),GetString(methname));
diff --git a/externals/grill/py/source/pyext.h b/externals/grill/py/source/pyext.h
index d05ea7e5..c073fa74 100644
--- a/externals/grill/py/source/pyext.h
+++ b/externals/grill/py/source/pyext.h
@@ -67,6 +67,7 @@ private:
static pyext *GetThis(PyObject *self);
V ClearBinding();
BL MakeInstance();
+ BL DoInit();
AtomList args;