aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py/source/pybase.cpp
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2005-07-09 13:03:34 +0000
committerThomas Grill <xovo@users.sourceforge.net>2005-07-09 13:03:34 +0000
commit29416a643b9c3d19a60b91b37a263d300c11486b (patch)
treedd28d4b6c6a6e4229de8c5e8ae76f4686df935c6 /externals/grill/py/source/pybase.cpp
parent897b80c5585f7c9031ff1aafb504c21a9d3b1606 (diff)
python-like dotted module.function syntax
reworked outbound message generation (now with symbols instead of one-element anythings) multiply inlets for py (hot and cold inlets) cleaned up float vs. int pyext tags pymeth object for object methods enable built-in functions sequence protocol for symbol type enabled built-in functions py: allow all callables svn path=/trunk/; revision=3310
Diffstat (limited to 'externals/grill/py/source/pybase.cpp')
-rw-r--r--externals/grill/py/source/pybase.cpp52
1 files changed, 38 insertions, 14 deletions
diff --git a/externals/grill/py/source/pybase.cpp b/externals/grill/py/source/pybase.cpp
index cc51a59e..3bc589de 100644
--- a/externals/grill/py/source/pybase.cpp
+++ b/externals/grill/py/source/pybase.cpp
@@ -62,6 +62,10 @@ void pybase::FreeThreadState()
PyObject *pybase::module_obj = NULL;
PyObject *pybase::module_dict = NULL;
+PyObject *pybase::builtins_obj = NULL;
+PyObject *pybase::builtins_dict = NULL;
+
+const t_symbol *pybase::sym_fint = NULL;
// -----------------------------------------------------------------------------------------------------------
@@ -128,6 +132,9 @@ void pybase::lib_setup()
Py_DECREF(gcobj);
}
+ builtins_obj = PyImport_ImportModule("__builtin__");
+ builtins_dict = PyModule_GetDict(builtins_obj); // borrowed reference
+
// add symbol type
initsymbol();
PyModule_AddObject(module_obj,"Symbol",(PyObject *)&pySymbol_Type);
@@ -144,9 +151,16 @@ void pybase::lib_setup()
initsamplebuffer();
PyModule_AddObject(module_obj,"Buffer",(PyObject *)&pySamplebuffer_Type);
+#if FLEXT_SYS == FLEXT_SYS_PD
+ sym_fint = sym_float;
+#else
+ sym_fint = sym_int;
+#endif
+
// -------------------------------------------------------------
FLEXT_SETUP(pyobj);
+ FLEXT_SETUP(pymeth);
FLEXT_SETUP(pyext);
FLEXT_DSP_SETUP(pydsp);
@@ -213,8 +227,11 @@ void pybase::GetDir(PyObject *obj,AtomList &lst)
if(!pvar)
PyErr_Print(); // no method found
else {
- if(!GetPyArgs(lst,pvar))
+ const t_symbol *sym = GetPyArgs(lst,pvar);
+ if(!sym)
post("py/pyext - Argument list could not be created");
+ else
+ FLEXT_ASSERT(sym == sym_list);
Py_DECREF(pvar);
}
@@ -294,9 +311,12 @@ void pybase::SetArgs()
bool pybase::ImportModule(const char *name)
{
- if(!name) return false;
- if(modname == name) return true;
- modname = name;
+ if(name) {
+ if(modname == name) return true;
+ modname = name;
+ }
+ else
+ modname.clear();
return ReloadModule();
}
@@ -321,9 +341,17 @@ bool pybase::ReloadModule()
bool ok = false;
SetArgs();
- PyObject *newmod = module
- ?PyImport_ReloadModule(module)
- :PyImport_ImportModule((char *)modname.c_str());
+ PyObject *newmod;
+
+ if(modname.length())
+ newmod = module
+ ?PyImport_ReloadModule(module)
+ :PyImport_ImportModule((char *)modname.c_str());
+ else {
+ // if no module name given, take py module
+ newmod = module_obj;
+ Py_INCREF(newmod);
+ }
if(!newmod) {
// unload faulty module
@@ -415,15 +443,11 @@ void pybase::AddCurrentPath(t_canvas *cnv)
bool pybase::OutObject(flext_base *ext,int o,PyObject *obj)
{
flext::AtomListStatic<16> lst;
- if(xlate?GetPyArgs(lst,obj):GetPyAtom(lst,obj)) {
+ const t_symbol *sym = xlate?GetPyArgs(lst,obj):GetPyAtom(lst,obj);
+ if(sym) {
// call to outlet _outside_ the Mutex lock!
// otherwise (if not detached) deadlock will occur
- if(lst.Count() && IsSymbol(lst[0]))
- ext->ToOutAnything(o,GetSymbol(lst[0]),lst.Count()-1,lst.Atoms()+1);
- else if(lst.Count() > 1)
- ext->ToOutList(o,lst);
- else
- ext->ToOutAtom(o,lst[0]);
+ ext->ToOutAnything(o,sym,lst.Count(),lst.Atoms());
return true;
}
else