From 58e4d7bbbdebe1ee96b318873391b634ca3b8a8f Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Tue, 6 Jan 2004 03:38:37 +0000 Subject: "" svn path=/trunk/; revision=1250 --- externals/grill/pool/readme.txt | 9 ++- externals/grill/py/readme.txt | 4 ++ externals/grill/py/source/main.cpp | 4 +- externals/grill/py/source/main.h | 2 +- externals/grill/py/source/pyargs.cpp | 110 +++++++++++++++++++---------------- externals/grill/py/source/pyext.cpp | 15 ++++- 6 files changed, 87 insertions(+), 57 deletions(-) diff --git a/externals/grill/pool/readme.txt b/externals/grill/pool/readme.txt index 62a14e0c..e0e51613 100644 --- a/externals/grill/pool/readme.txt +++ b/externals/grill/pool/readme.txt @@ -1,6 +1,6 @@ pool - a hierarchical storage object for PD and Max/MSP -Copyright (c) 2002-2003 Thomas Grill (xovo@gmx.net) +Copyright (c) 2002-2004 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. @@ -37,7 +37,7 @@ pd - Windows: ------------- o Borland C++ 5.5 (free): edit "config-pd-bcc.txt" & run "build-pd-bcc.bat" -o Microsoft Visual C++ 6: edit the project file "pool.dsp" & build +o Microsoft Visual C++ 6/7: edit "config-pd-msvc.txt" & run "build-pd-msvc.bat" pd - linux: ----------- @@ -51,6 +51,11 @@ Max/MSP - MacOS9/X: ------------------- o CodeWarrior: edit "pool.cw" and build +Max/MSP - Windows: +------------------- +o Microsoft Visual C++ 7: edit "config-max-msvc.txt" & run "build-max-msvc.bat" + + ---------------------------------------------------------------------------- Version history: diff --git a/externals/grill/py/readme.txt b/externals/grill/py/readme.txt index c3ad37a9..2420cddc 100644 --- a/externals/grill/py/readme.txt +++ b/externals/grill/py/readme.txt @@ -82,6 +82,9 @@ o GCC: edit "config-pd-darwin.txt" & run "sh build-pd-darwin.sh" Version history: +0.1.3: +- FIX: class variables are now set atomic if parameter list has only 1 element + 0.1.2: - CHANGE: updates for flext 0.4.1 - method registering within class scope - FIX: bugs in bound.cpp (object_free calls) @@ -123,6 +126,7 @@ TODO list: general: - Documentation and better example patches +- better error reporting for runtime errors features: - enable multiple interpreters? diff --git a/externals/grill/py/source/main.cpp b/externals/grill/py/source/main.cpp index dbcd27f9..84698211 100644 --- a/externals/grill/py/source/main.cpp +++ b/externals/grill/py/source/main.cpp @@ -2,7 +2,7 @@ py/pyext - python external object for PD and MaxMSP -Copyright (c) 2002-2003 Thomas Grill (xovo@gmx.net) +Copyright (c) 2002-2004 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. @@ -13,7 +13,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. V py::lib_setup() { post(""); - post("py/pyext %s - python script objects, (C)2002,2003 Thomas Grill",PY__VERSION); + post("py/pyext %s - python script objects, (C)2002-2004 Thomas Grill",PY__VERSION); post(""); FLEXT_SETUP(pyobj); diff --git a/externals/grill/py/source/main.h b/externals/grill/py/source/main.h index b0bf4711..407fc8df 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.5 #endif -#define PY__VERSION "0.1.2" +#define PY__VERSION "0.1.3pre" #define PYEXT_MODULE "pyext" // name for module 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; } diff --git a/externals/grill/py/source/pyext.cpp b/externals/grill/py/source/pyext.cpp index b8763771..799de20a 100644 --- a/externals/grill/py/source/pyext.cpp +++ b/externals/grill/py/source/pyext.cpp @@ -2,7 +2,7 @@ py/pyext - python script object for PD and MaxMSP -Copyright (c) 2002-2003 Thomas Grill (xovo@gmx.net) +Copyright (c) 2002-2004 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. @@ -339,10 +339,19 @@ void pyext::m_set(int argc,const t_atom *argv) post("%s - set: Python variable %s not found",thisName(),ch); } else { - PyObject *pval = MakePyArgs(sym_list,AtomList(argc-1,argv+1),-1,false); - if(!pval) + PyObject *pval = MakePyArgs(NULL,AtomList(argc-1,argv+1),-1,false); + + if(!pval) PyErr_Print(); else { + if(PySequence_Size(pval) == 1) { + // reduce lists of one element to element itself + + PyObject *val1 = PySequence_GetItem(pval,0); + Py_DECREF(pval); + pval = val1; + } + PyObject_SetAttrString(pyobj,ch,pval); Py_DECREF(pval); } -- cgit v1.2.1