aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py/source/pyargs.cpp
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2004-01-06 03:38:37 +0000
committerThomas Grill <xovo@users.sourceforge.net>2004-01-06 03:38:37 +0000
commit58e4d7bbbdebe1ee96b318873391b634ca3b8a8f (patch)
treeb872cc12cb79f7746c5fd5c0048188093c8b1755 /externals/grill/py/source/pyargs.cpp
parent26bce99988ed7f18cef77ede2be92acd42ebb60c (diff)
""
svn path=/trunk/; revision=1250
Diffstat (limited to 'externals/grill/py/source/pyargs.cpp')
-rw-r--r--externals/grill/py/source/pyargs.cpp110
1 files changed, 61 insertions, 49 deletions
diff --git a/externals/grill/py/source/pyargs.cpp b/externals/grill/py/source/pyargs.cpp
index 5ed3a89c..cf6d41d0 100644
--- a/externals/grill/py/source/pyargs.cpp
+++ b/externals/grill/py/source/pyargs.cpp
@@ -10,60 +10,72 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include "main.h"
+static PyObject *MakePyAtom(const t_atom &at)
+{
+ if(flext::IsFloat(at)) return PyFloat_FromDouble((D)flext::GetFloat(at));
+ else if(flext::IsInt(at)) return PyInt_FromLong(flext::GetInt(at));
+ else if(flext::IsSymbol(at)) return PyString_FromString(flext::GetString(at));
+// else if(flext::IsPointer(at)) return NULL; // not handled
+ else return NULL;
+}
PyObject *py::MakePyArgs(const t_symbol *s,const AtomList &args,I inlet,BL withself)
{
PyObject *pArgs;
- BL any = IsAnything(s);
- pArgs = PyTuple_New(args.Count()+(any?1:0)+(inlet >= 0?1:0));
-
- I pix = 0;
-
- if(inlet >= 0) {
- PyObject *pValue = PyInt_FromLong(inlet);
-
- // reference stolen:
- PyTuple_SetItem(pArgs, pix++, pValue);
- }
-
- I ix;
- PyObject *tmp;
- if(!withself || args.Count() < (any?1:2)) tmp = pArgs,ix = pix;
- else tmp = PyTuple_New(args.Count()+(any?1:0)),ix = 0;
-
- if(any) {
- PyObject *pValue = PyString_FromString(GetString(s));
-
- // reference stolen here:
- PyTuple_SetItem(tmp, ix++, pValue);
- }
-
- for(I i = 0; i < args.Count(); ++i) {
- PyObject *pValue = NULL;
-
- if(IsFloat(args[i])) pValue = PyFloat_FromDouble((D)GetFloat(args[i]));
- else if(IsInt(args[i])) pValue = PyInt_FromLong(GetInt(args[i]));
- else if(IsSymbol(args[i])) pValue = PyString_FromString(GetString(args[i]));
- else if(IsPointer(args[i])) pValue = NULL; // not handled
-
- if(!pValue) {
- post("py/pyext: cannot convert argument %i",any?i+1:i);
- continue;
- }
-
- /* pValue reference stolen here: */
- PyTuple_SetItem(tmp, ix++, pValue);
- }
-
- if(tmp != pArgs) {
- PyTuple_SetItem(pArgs, pix++, tmp);
-#if PY_VERSION_HEX >= 0x02020000
- _PyTuple_Resize(&pArgs,pix);
-#else
- _PyTuple_Resize(&pArgs,pix,0);
-#endif
- }
+/*
+ if(!s && args.Count() == 1) {
+ pArgs = MakePyAtom(args[0]);
+ if(!pArgs)
+ post("py/pyext: cannot convert argument(s)");
+ }
+ else
+*/
+ {
+ BL any = IsAnything(s);
+ pArgs = PyTuple_New(args.Count()+(any?1:0)+(inlet >= 0?1:0));
+
+ I pix = 0;
+
+ if(inlet >= 0) {
+ PyObject *pValue = PyInt_FromLong(inlet);
+
+ // reference stolen:
+ PyTuple_SetItem(pArgs, pix++, pValue);
+ }
+
+ I ix;
+ PyObject *tmp;
+ if(!withself || args.Count() < (any?1:2)) tmp = pArgs,ix = pix;
+ else tmp = PyTuple_New(args.Count()+(any?1:0)),ix = 0;
+
+ if(any) {
+ PyObject *pValue = PyString_FromString(GetString(s));
+
+ // reference stolen here:
+ PyTuple_SetItem(tmp, ix++, pValue);
+ }
+
+ for(I i = 0; i < args.Count(); ++i) {
+ PyObject *pValue = MakePyAtom(args[i]);
+ if(!pValue) {
+ post("py/pyext: cannot convert argument %i",any?i+1:i);
+ continue;
+ }
+
+ /* pValue reference stolen here: */
+ PyTuple_SetItem(tmp, ix++, pValue);
+ }
+
+ if(tmp != pArgs) {
+ PyTuple_SetItem(pArgs, pix++, tmp);
+ #if PY_VERSION_HEX >= 0x02020000
+ _PyTuple_Resize(&pArgs,pix);
+ #else
+ _PyTuple_Resize(&pArgs,pix,0);
+ #endif
+ }
+ }
return pArgs;
}