aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py/source
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2004-01-07 03:38:25 +0000
committerThomas Grill <xovo@users.sourceforge.net>2004-01-07 03:38:25 +0000
commitd563db671892f0719195aeeb89cac6ee3fe7c69e (patch)
tree2724d6e05233b1b7c5e475938553b1b907c2cbf6 /externals/grill/py/source
parent58e4d7bbbdebe1ee96b318873391b634ca3b8a8f (diff)
""
svn path=/trunk/; revision=1251
Diffstat (limited to 'externals/grill/py/source')
-rw-r--r--externals/grill/py/source/main.cpp21
-rw-r--r--externals/grill/py/source/main.h4
-rw-r--r--externals/grill/py/source/pyargs.cpp16
-rw-r--r--externals/grill/py/source/pyext.cpp5
-rw-r--r--externals/grill/py/source/pyext.h7
5 files changed, 40 insertions, 13 deletions
diff --git a/externals/grill/py/source/main.cpp b/externals/grill/py/source/main.cpp
index 84698211..72ccaa82 100644
--- a/externals/grill/py/source/main.cpp
+++ b/externals/grill/py/source/main.cpp
@@ -128,21 +128,18 @@ py::~py()
}
-void py::m__dir(PyObject *obj)
+void py::GetDir(PyObject *obj,AtomList &lst)
{
if(obj) {
PY_LOCK
PyObject *pvar = PyObject_Dir(obj);
- if(pvar == NULL) {
+ if(!pvar)
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;
+ AtomList *l = GetPyArgs(pvar);
+ if(l) {
+ lst = *l; delete l;
}
else
post("%s - %s: List could not be created",thisName(),GetString(thisTag()));
@@ -153,6 +150,14 @@ void py::m__dir(PyObject *obj)
}
}
+void py::m__dir(PyObject *obj)
+{
+ AtomList lst;
+ GetDir(obj,lst);
+ // dump dir to attribute outlet
+ ToOutAnything(GetOutAttr(),thisTag(),lst.Count(),lst.Atoms());
+}
+
V py::m__doc(PyObject *obj)
{
if(obj) {
diff --git a/externals/grill/py/source/main.h b/externals/grill/py/source/main.h
index 407fc8df..b293246e 100644
--- a/externals/grill/py/source/main.h
+++ b/externals/grill/py/source/main.h
@@ -69,6 +69,7 @@ protected:
V m__doc(PyObject *obj);
V m_dir() { m__dir(module); }
+ V mg_dir(AtomList &lst) { m__dir(module); }
V m_doc() { m__doc(dict); }
PyObject *module,*dict; // inherited user class module and associated dictionary
@@ -76,6 +77,8 @@ protected:
static I pyref;
static const C *py_doc;
+ V GetDir(PyObject *obj,AtomList &lst);
+
V GetModulePath(const C *mod,C *dir,I len);
V AddToPath(const C *dir);
V SetArgs(I argc,const t_atom *argv);
@@ -137,6 +140,7 @@ protected:
FLEXT_ATTRVAR_B(detach)
FLEXT_CALLBACK_V(m_stop)
FLEXT_CALLBACK(m_dir)
+ FLEXT_ATTRGET_V(mg_dir)
FLEXT_CALLBACK(m_doc)
FLEXT_CALLBACK_T(tick)
};
diff --git a/externals/grill/py/source/pyargs.cpp b/externals/grill/py/source/pyargs.cpp
index cf6d41d0..595dce0c 100644
--- a/externals/grill/py/source/pyargs.cpp
+++ b/externals/grill/py/source/pyargs.cpp
@@ -12,11 +12,19 @@ WARRANTIES, see the file, "license.txt," in this distribution.
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));
+ if(flext::IsSymbol(at)) return PyString_FromString(flext::GetString(at));
// else if(flext::IsPointer(at)) return NULL; // not handled
- else return NULL;
+ else if(flext::CanbeInt(at) && flext::CanbeFloat(at)) {
+ // if a number can be an integer... let at be an integer!
+ int ival = flext::GetAInt(at);
+ double fval = flext::GetAFloat(at);
+ return (double)ival == fval?PyInt_FromLong(ival):PyFloat_FromDouble(fval);
+ }
+ // these following should never happen
+ else if(flext::IsFloat(at)) return PyFloat_FromDouble((D)flext::GetFloat(at));
+ else if(flext::IsInt(at)) return PyInt_FromLong(flext::GetInt(at));
+
+ return NULL;
}
PyObject *py::MakePyArgs(const t_symbol *s,const AtomList &args,I inlet,BL withself)
diff --git a/externals/grill/py/source/pyext.cpp b/externals/grill/py/source/pyext.cpp
index 799de20a..e7b12756 100644
--- a/externals/grill/py/source/pyext.cpp
+++ b/externals/grill/py/source/pyext.cpp
@@ -12,7 +12,7 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include <flinternal.h>
-FLEXT_LIB_V("pyext",pyext)
+FLEXT_LIB_V("pyext pyx",pyext)
V pyext::Setup(t_classid c)
{
@@ -23,6 +23,9 @@ V pyext::Setup(t_classid c)
FLEXT_CADDMETHOD_(c,0,"doc",m_doc);
FLEXT_CADDMETHOD_(c,0,"doc+",m_doc_);
+ FLEXT_CADDATTR_VAR(c,"args",args,ms_args);
+ FLEXT_CADDATTR_GET(c,"dir+",mg_dir_);
+
#ifdef FLEXT_THREADS
FLEXT_CADDATTR_VAR1(c,"detach",detach);
FLEXT_CADDMETHOD_(c,0,"stop",m_stop);
diff --git a/externals/grill/py/source/pyext.h b/externals/grill/py/source/pyext.h
index 8fe99ccc..09a7a49e 100644
--- a/externals/grill/py/source/pyext.h
+++ b/externals/grill/py/source/pyext.h
@@ -48,7 +48,9 @@ protected:
V m_reload();
V m_reload_(I argc,const t_atom *argv);
+ V ms_args(const AtomList &a) { m_reload_(a.Count(),a.Atoms()); }
V m_dir_() { m__dir(pyobj); }
+ V mg_dir_(AtomList &lst) { GetDir(pyobj,lst); }
V m_doc_() { m__doc(pyobj); }
virtual V m_help();
@@ -108,7 +110,12 @@ private:
FLEXT_CALLBACK(m_reload)
FLEXT_CALLBACK_V(m_reload_)
FLEXT_CALLBACK(m_dir_)
+ FLEXT_CALLGET_V(mg_dir_)
FLEXT_CALLBACK(m_doc_)
+ FLEXT_CALLGET_V(mg_doc_)
+
+ FLEXT_ATTRGET_V(args)
+ FLEXT_CALLSET_V(ms_args)
FLEXT_CALLBACK_S(m_get)
FLEXT_CALLBACK_V(m_set)