aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py
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
parentba5b1684b1279115b95e274d1854fb14fe49587e (diff)
""
svn path=/trunk/; revision=1965
Diffstat (limited to 'externals/grill/py')
-rw-r--r--externals/grill/py/pd/pak.pd28
-rw-r--r--externals/grill/py/scripts/pak.py14
-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
6 files changed, 105 insertions, 39 deletions
diff --git a/externals/grill/py/pd/pak.pd b/externals/grill/py/pd/pak.pd
new file mode 100644
index 00000000..99d0ac5b
--- /dev/null
+++ b/externals/grill/py/pd/pak.pd
@@ -0,0 +1,28 @@
+#N canvas 463 293 278 228 12;
+#X obj 17 32 nbx 5 14 -1e+037 1e+037 0 0 empty empty empty 0 -6 0 10
+-262144 -1 -1 18 256;
+#X obj 34 52 nbx 5 14 -1e+037 1e+037 0 0 empty empty empty 0 -6 0 10
+-262144 -1 -1 11 256;
+#X obj 56 68 nbx 5 14 -1e+037 1e+037 0 0 empty empty empty 0 -6 0 10
+-262144 -1 -1 13 256;
+#X obj 68 88 nbx 5 14 -1e+037 1e+037 0 0 empty empty empty 0 -6 0 10
+-262144 -1 -1 21 256;
+#X obj 118 29 nbx 5 14 -1e+037 1e+037 0 0 empty empty empty 0 -6 0
+10 -262144 -1 -1 13 256;
+#X obj 135 49 nbx 5 14 -1e+037 1e+037 0 0 empty empty empty 0 -6 0
+10 -262144 -1 -1 13 256;
+#X obj 157 65 nbx 5 14 -1e+037 1e+037 0 0 empty empty empty 0 -6 0
+10 -262144 -1 -1 10 256;
+#X obj 169 85 nbx 5 14 -1e+037 1e+037 0 0 empty empty empty 0 -6 0
+10 -262144 -1 -1 11 256;
+#X obj 36 168 print;
+#X obj 37 129 pyx pak pak 8;
+#X connect 0 0 9 1;
+#X connect 1 0 9 2;
+#X connect 2 0 9 3;
+#X connect 3 0 9 4;
+#X connect 4 0 9 5;
+#X connect 5 0 9 6;
+#X connect 6 0 9 7;
+#X connect 7 0 9 8;
+#X connect 9 0 8 0;
diff --git a/externals/grill/py/scripts/pak.py b/externals/grill/py/scripts/pak.py
new file mode 100644
index 00000000..17841630
--- /dev/null
+++ b/externals/grill/py/scripts/pak.py
@@ -0,0 +1,14 @@
+import pyext
+
+class pak(pyext._class):
+ def __init__(self,n):
+ # n should be type-checked
+ self._inlets = n
+ self._outlets = 1
+ # initialize list
+ self.lst = [0 for x in range(n)]
+
+ def _anything_(self,n,args):
+ # args should be type-checked!
+ self.lst[n-1] = args
+ self._outlet(1,self.lst)
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;