Update of /cvsroot/pure-data/externals/grill/py/source In directory sc8-pr-cvs1:/tmp/cvs-serv24266/source
Modified Files: clmeth.cpp main.cpp main.h py.cpp pyext.cpp pyext.h Log Message: ""
Index: clmeth.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/clmeth.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** clmeth.cpp 20 Oct 2003 02:38:10 -0000 1.4 --- clmeth.cpp 21 Oct 2003 02:38:31 -0000 1.5 *************** *** 195,199 **** else { pyext *ext = GetThis(self); ! ext->m_detach(val != 0); }
--- 195,199 ---- else { pyext *ext = GetThis(self); ! ext->detach = val != 0; }
Index: main.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/main.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** main.cpp 20 Oct 2003 02:38:10 -0000 1.5 --- main.cpp 21 Oct 2003 02:38:31 -0000 1.6 *************** *** 39,43 **** { Lock(); - // under Max/MSP @ OS9: doesn't survive next line.....
if(!(pyref++)) { --- 39,42 ---- *************** *** 122,139 ****
! V py::m_doc() { ! if(dict) { ! PyObject *docf = PyDict_GetItemString(dict,"__doc__"); // borrowed!!! if(docf && PyString_Check(docf)) { post(""); post(PyString_AsString(docf)); } } }
- - V py::SetArgs(I argc,const t_atom *argv) { --- 121,165 ----
! void py::m__dir(PyObject *obj) { ! if(obj) { ! PY_LOCK ! ! PyObject *pvar = PyObject_Dir(obj); ! if(pvar == NULL) { ! PyErr_Print(); // no method found ! } ! else { ! AtomList *lst = GetPyArgs(pvar); ! if(lst) { ! // dump dir to attribute outlet ! ToOutAnything(GetOutAttr(),thisTag(),lst->Count(),lst->Atoms()); ! delete lst; ! } ! else ! post("%s - %s: List could not be created",thisName(),GetString(thisTag())); ! Py_DECREF(pvar); ! } ! ! PY_UNLOCK ! } ! } ! ! V py::m__doc(PyObject *obj) ! { ! if(obj) { ! PY_LOCK ! ! PyObject *docf = PyDict_GetItemString(obj,"__doc__"); // borrowed!!! if(docf && PyString_Check(docf)) { post(""); post(PyString_AsString(docf)); } + + PY_UNLOCK } }
V py::SetArgs(I argc,const t_atom *argv) { *************** *** 203,206 **** --- 229,241 ---- #elif FLEXT_SYS == FLEXT_SYS_MAX // how do i get the path in Max/MSP? + short path; + long type; + char smod[256]; + strcat(strcpy(smod,mod),".py"); + if(!locatefile_extended(smod,&path,&type,&type,-1)) + path_topathname(path,NULL,dir); + else + // not found + *dir = 0; #else *dir = 0; *************** *** 226,229 **** } } - - --- 261,262 ----
Index: main.h =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/main.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** main.h 20 Oct 2003 02:38:10 -0000 1.7 --- main.h 21 Oct 2003 02:38:31 -0000 1.8 *************** *** 12,15 **** --- 12,17 ---- #define __MAIN_H
+ #define FLEXT_ATTRIBUTES 1 + #include <flext.h> #include <Python.h> *************** *** 60,64 **** protected:
! V m_doc();
PyObject *module,*dict; // inherited user class module and associated dictionary --- 62,70 ---- protected:
! V m__dir(PyObject *obj); ! V m__doc(PyObject *obj); ! ! V m_dir() { m__dir(module); } ! V m_doc() { m__doc(dict); }
PyObject *module,*dict; // inherited user class module and associated dictionary *************** *** 100,104 **** // ----thread stuff ------------
- V m_detach(BL det) { detach = det; } virtual V m_stop(int argc,const t_atom *argv);
--- 106,109 ---- *************** *** 126,131 **** // callbacks
! FLEXT_CALLBACK_B(m_detach) FLEXT_CALLBACK_V(m_stop) FLEXT_CALLBACK(m_doc) FLEXT_CALLBACK_T(tick) --- 131,137 ---- // callbacks
! FLEXT_ATTRVAR_B(detach) FLEXT_CALLBACK_V(m_stop) + FLEXT_CALLBACK(m_dir) FLEXT_CALLBACK(m_doc) FLEXT_CALLBACK_T(tick)
Index: py.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/py.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** py.cpp 20 Oct 2003 02:38:10 -0000 1.6 --- py.cpp 21 Oct 2003 02:38:31 -0000 1.7 *************** *** 30,34 **** V m_reload_(I argc,const t_atom *argv); V m_set(I argc,const t_atom *argv); ! V m_doc_();
virtual V m_help(); --- 30,35 ---- V m_reload_(I argc,const t_atom *argv); V m_set(I argc,const t_atom *argv); ! V m_dir_() { m__dir(function); } ! V m_doc_() { m__doc(function); }
virtual V m_help(); *************** *** 57,60 **** --- 58,62 ---- FLEXT_CALLBACK_V(m_reload_) FLEXT_CALLBACK_V(m_set) + FLEXT_CALLBACK(m_dir_) FLEXT_CALLBACK(m_doc_)
*************** *** 83,89 **** FLEXT_CADDMETHOD_(c,0,"doc+",m_doc_); #ifdef FLEXT_THREADS ! FLEXT_CADDMETHOD_(c,0,"detach",m_detach); FLEXT_CADDMETHOD_(c,0,"stop",m_stop); #endif
FLEXT_CADDMETHOD_(c,1,"float",m_py_float); --- 85,93 ---- FLEXT_CADDMETHOD_(c,0,"doc+",m_doc_); #ifdef FLEXT_THREADS ! FLEXT_CADDATTR_VAR1(c,"detach",detach); FLEXT_CADDMETHOD_(c,0,"stop",m_stop); #endif + FLEXT_CADDMETHOD_(c,0,"dir",m_dir); + FLEXT_CADDMETHOD_(c,0,"dir+",m_dir_);
FLEXT_CADDMETHOD_(c,1,"float",m_py_float); *************** *** 202,228 **** }
- - V pyobj::m_doc_() - { - PY_LOCK - - if(function) { - PyObject *docf = PyObject_GetAttrString(function,"__doc__"); // borrowed!!! - if(docf && PyString_Check(docf)) { - post(""); - post(PyString_AsString(docf)); - } - } - - PY_UNLOCK - } - - V pyobj::m_help() { post(""); ! post("py %s - python script object, (C)2002 Thomas Grill",PY__VERSION); #ifdef FLEXT_DEBUG ! post("compiled on " __DATE__ " " __TIME__); #endif
--- 206,215 ---- }
V pyobj::m_help() { post(""); ! post("py %s - python script object, (C)2002,2003 Thomas Grill",PY__VERSION); #ifdef FLEXT_DEBUG ! post("DEBUG VERSION, compiled on " __DATE__ " " __TIME__); #endif
Index: pyext.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pyext.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** pyext.cpp 20 Oct 2003 02:38:10 -0000 1.8 --- pyext.cpp 21 Oct 2003 02:38:31 -0000 1.9 *************** *** 19,29 **** FLEXT_CADDMETHOD_(c,0,"reload.",m_reload); FLEXT_CADDMETHOD_(c,0,"reload",m_reload_); FLEXT_CADDMETHOD_(c,0,"doc",m_doc); FLEXT_CADDMETHOD_(c,0,"doc+",m_doc_);
#ifdef FLEXT_THREADS ! FLEXT_CADDMETHOD_(c,0,"detach",m_detach); FLEXT_CADDMETHOD_(c,0,"stop",m_stop); #endif }
--- 19,34 ---- FLEXT_CADDMETHOD_(c,0,"reload.",m_reload); FLEXT_CADDMETHOD_(c,0,"reload",m_reload_); + FLEXT_CADDMETHOD_(c,0,"dir",m_dir); + FLEXT_CADDMETHOD_(c,0,"dir+",m_dir_); FLEXT_CADDMETHOD_(c,0,"doc",m_doc); FLEXT_CADDMETHOD_(c,0,"doc+",m_doc_);
#ifdef FLEXT_THREADS ! FLEXT_CADDATTR_VAR1(c,"detach",detach); FLEXT_CADDMETHOD_(c,0,"stop",m_stop); #endif + + FLEXT_CADDMETHOD_(c,0,"get",m_get); + FLEXT_CADDMETHOD_(c,0,"set",m_set); }
*************** *** 38,41 **** --- 43,60 ----
+ #if FLEXT_SYS == FLEXT_SYS_MAX + static short patcher_myvol(t_patcher *x) + { + t_box *w; + if (x->p_vol) + return x->p_vol; + else if (w = (t_box *)x->p_vnewobj) + return patcher_myvol(w->b_patcher); + else + return 0; + } + #endif + + I pyext::pyextref = 0; PyObject *pyext::class_obj = NULL; *************** *** 90,103 **** // init script module if(argc >= 1) { ! C dir[1024]; #if FLEXT_SYS == FLEXT_SYS_PD // add dir of current patch to path ! strcpy(dir,GetString(canvas_getdir(thisCanvas()))); ! AddToPath(dir); // add current dir to path ! strcpy(dir,GetString(canvas_getcurrentdir())); ! AddToPath(dir); ! #else ! #pragma message("Adding current dir to path is not implemented") #endif
--- 109,125 ---- // init script module if(argc >= 1) { ! char dir[1024]; ! #if FLEXT_SYS == FLEXT_SYS_PD // add dir of current patch to path ! AddToPath(GetString(canvas_getdir(thisCanvas()))); // add current dir to path ! AddToPath(GetString(canvas_getcurrentdir())); ! #elif FLEXT_SYS == FLEXT_SYS_MAX ! short path = patcher_myvol(thisCanvas()); ! path_topathname(path,NULL,dir); ! AddToPath(dir); ! #else ! #pragma message("Adding current dir to path is not implemented") #endif
*************** *** 275,294 **** }
! V pyext::m_doc_() { ! if(pyobj) { ! PY_LOCK ! ! PyObject *docf = PyObject_GetAttrString(pyobj,"__doc__"); // borrowed!!! ! if(docf && PyString_Check(docf)) { ! post(""); ! post(PyString_AsString(docf)); ! }
! PY_UNLOCK } }
--- 297,355 ---- }
! void pyext::m_get(const t_symbol *s) { ! PY_LOCK
! PyObject *pvar = PyObject_GetAttrString(pyobj,const_cast<char *>(GetString(s))); /* fetch bound method */ ! if(pvar == NULL) { ! PyErr_Clear(); // no method found ! post("%s - get: Python variable %s not found",thisName(),GetString(s)); } + else { + AtomList *lst = GetPyArgs(pvar); + if(lst) { + // dump value to attribute outlet + AtomAnything out("get",lst->Count()+1); + SetSymbol(out[0],s); + out.Set(lst->Count(),lst->Atoms(),1); + delete lst; + + ToOutAnything(GetOutAttr(),out); + } + else + post("%s - get: List could not be created",thisName()); + Py_DECREF(pvar); + } + + PY_UNLOCK }
+ void pyext::m_set(int argc,const t_atom *argv) + { + PY_LOCK
+ if(argc < 2 || !IsString(argv[0])) + post("%s - Syntax: set varname arguments...",thisName()); + else if(*GetString(argv[0]) == '_') + post("%s - set: variables with leading _ are reserved and can't be set",thisName()); + else { + char *ch = const_cast<char *>(GetString(argv[0])); + if(!PyObject_HasAttrString(pyobj,ch)) { + PyErr_Clear(); // no method found + 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) + PyErr_Print(); + else { + PyObject_SetAttrString(pyobj,ch,pval); + Py_DECREF(pval); + } + } + } + + PY_UNLOCK + }
*************** *** 308,314 **** { post(""); ! post("pyext %s - python script object, (C)2002 Thomas Grill",PY__VERSION); #ifdef FLEXT_DEBUG ! post("compiled on " __DATE__ " " __TIME__); #endif
--- 369,375 ---- { post(""); ! post("pyext %s - python script object, (C)2002,2003 Thomas Grill",PY__VERSION); #ifdef FLEXT_DEBUG ! post("DEBUG VERSION, compiled on " __DATE__ " " __TIME__); #endif
*************** *** 346,350 **** ret = PyEval_CallObject(pmeth, pargs); if (ret == NULL) // function not found resp. arguments not matching ! #if 1 //def FLEXT_DEBUG PyErr_Print(); #else --- 407,411 ---- ret = PyEval_CallObject(pmeth, pargs); if (ret == NULL) // function not found resp. arguments not matching ! #ifdef FLEXT_DEBUG PyErr_Print(); #else
Index: pyext.h =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/pyext.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** pyext.h 20 Oct 2003 02:38:10 -0000 1.8 --- pyext.h 21 Oct 2003 02:38:31 -0000 1.9 *************** *** 49,55 **** V m_reload(); V m_reload_(I argc,const t_atom *argv); ! V m_doc_(); virtual V m_help();
const t_symbol *methname; PyObject *pyobj; --- 49,59 ---- V m_reload(); V m_reload_(I argc,const t_atom *argv); ! V m_dir_() { m__dir(pyobj); } ! V m_doc_() { m__doc(pyobj); } virtual V m_help();
+ V m_get(const t_symbol *s); + V m_set(I argc,const t_atom *argv); + const t_symbol *methname; PyObject *pyobj; *************** *** 104,108 **** --- 108,116 ---- FLEXT_CALLBACK(m_reload) FLEXT_CALLBACK_V(m_reload_) + FLEXT_CALLBACK(m_dir_) FLEXT_CALLBACK(m_doc_) + + FLEXT_CALLBACK_S(m_get) + FLEXT_CALLBACK_V(m_set) };