aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py
diff options
context:
space:
mode:
Diffstat (limited to 'externals/grill/py')
-rw-r--r--externals/grill/py/readme.txt1
-rw-r--r--externals/grill/py/scripts/simple.py4
-rw-r--r--externals/grill/py/source/clmeth.cpp1
-rw-r--r--externals/grill/py/source/main.cpp75
-rw-r--r--externals/grill/py/source/main.h6
5 files changed, 80 insertions, 7 deletions
diff --git a/externals/grill/py/readme.txt b/externals/grill/py/readme.txt
index f6c05006..1573c931 100644
--- a/externals/grill/py/readme.txt
+++ b/externals/grill/py/readme.txt
@@ -89,6 +89,7 @@ Version history:
- FIX: parameters to Python functions are treated as integers when they can be.
- ADD: inlet and outlet count can be given for pyext, python _inlet and _outlet members are ignored then
- FIX: crash if script or class names are non-strings
+- FIX: long multi-line doc strings are now printed correctly
0.1.2:
- CHANGE: updates for flext 0.4.1 - method registering within class scope
diff --git a/externals/grill/py/scripts/simple.py b/externals/grill/py/scripts/simple.py
index 2962ab39..f4a90398 100644
--- a/externals/grill/py/scripts/simple.py
+++ b/externals/grill/py/scripts/simple.py
@@ -84,10 +84,10 @@ class ex1(pyext._class):
print "Bang into first inlet"
def float_1(self,f):
- print "Float ",f," into first inlet"
+ print "Float",f,"into first inlet"
def list_1(self,s):
- print "List ",s," into first inlet"
+ print "List",s,"into first inlet"
# methods for second inlet
diff --git a/externals/grill/py/source/clmeth.cpp b/externals/grill/py/source/clmeth.cpp
index 0f4ad23e..a17c010a 100644
--- a/externals/grill/py/source/clmeth.cpp
+++ b/externals/grill/py/source/clmeth.cpp
@@ -131,7 +131,6 @@ PyObject* pyext::pyext_getattr(PyObject *,PyObject *args)
return ret;
}
-
//! Send message to outlet
PyObject *pyext::pyext_outlet(PyObject *,PyObject *args)
{
diff --git a/externals/grill/py/source/main.cpp b/externals/grill/py/source/main.cpp
index c311785b..e552bc5a 100644
--- a/externals/grill/py/source/main.cpp
+++ b/externals/grill/py/source/main.cpp
@@ -35,6 +35,13 @@ PyObject *py::module_obj = NULL;
PyObject *py::module_dict = NULL;
+static PyMethodDef StdOut_Methods[] =
+{
+ { "write", py::StdOut_Write, 1 },
+ { NULL, NULL, }
+};
+
+
py::py():
module(NULL),
detach(false),shouldexit(false),thrcount(0),
@@ -66,6 +73,10 @@ py::py():
module_dict = PyModule_GetDict(module_obj);
PyModule_AddStringConstant(module_obj,"__doc__",(C *)py_doc);
+
+ // redirect stdout
+ PyObject* py_out = Py_InitModule("stdout", StdOut_Methods);
+ PySys_SetObject("stdout", py_out);
}
else {
PY_LOCK
@@ -166,7 +177,28 @@ V py::m__doc(PyObject *obj)
PyObject *docf = PyDict_GetItemString(obj,"__doc__"); // borrowed!!!
if(docf && PyString_Check(docf)) {
post("");
- post(PyString_AsString(docf));
+ const char *s = PyString_AsString(docf);
+
+ // FIX: Python doc strings can easily be larger than 1k characters
+ // -> split into separate lines
+ for(;;) {
+ char buf[1024];
+ char *nl = strchr(s,'\n');
+ if(!nl) {
+ // no more newline found
+ post(s);
+ break;
+ }
+ else {
+ // copy string before newline to temp buffer and post
+ int l = nl-s;
+ if(l >= sizeof(buf)) l = sizeof buf-1;
+ strncpy(buf,s,l); // copy all but newline
+ buf[l] = 0;
+ post(buf);
+ s = nl+1; // set after newline
+ }
+ }
}
PY_UNLOCK
@@ -263,7 +295,7 @@ V py::AddToPath(const C *dir)
int i,n = PyList_Size(pobj);
for(i = 0; i < n; ++i) {
PyObject *pt = PyList_GetItem(pobj,i);
- if(PyString_Check(pt) && !strcmp(dir,PyString_AsString(pt))) break;
+ if(PyString_Check(pt) && !strcmp(dir,PyString_AS_STRING(pt))) break;
}
if(i == n) { // string is not yet existent in path
PyObject *ps = PyString_FromString(dir);
@@ -273,3 +305,42 @@ V py::AddToPath(const C *dir)
PySys_SetObject("path",pobj);
}
}
+
+static PyObject *output = NULL;
+
+// post to the console
+PyObject* py::StdOut_Write(PyObject* self, PyObject* args)
+{
+ if(PySequence_Check(args)) {
+ int sz = PySequence_Size(args);
+ for(int i = 0; i < sz; ++i) {
+ PyObject *val = PySequence_GetItem(args,i); // borrowed
+ PyObject *str = PyObject_Str(val);
+ char *cstr = PyString_AS_STRING(str);
+ char *lf = strchr(cstr,'\n');
+
+ // line feed in string
+ if(!lf) {
+ // no -> just append
+ if(output)
+ PyString_ConcatAndDel(&output,str);
+ else
+ output = str;
+ }
+ else {
+ // yes -> append up to line feed, reset output buffer to string remainder
+ PyObject *part = PyString_FromStringAndSize(cstr,lf-cstr);
+ if(output)
+ PyString_ConcatAndDel(&output,part);
+ else
+ output = part;
+ post(PyString_AS_STRING(output));
+ Py_DECREF(output);
+ output = PyString_FromString(lf+1);
+ }
+ }
+ }
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
diff --git a/externals/grill/py/source/main.h b/externals/grill/py/source/main.h
index 612c1c45..d6ca52cb 100644
--- a/externals/grill/py/source/main.h
+++ b/externals/grill/py/source/main.h
@@ -25,8 +25,8 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include <unistd.h>
#endif
-#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 405)
-#error You need at least flext version 0.4.5
+#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406)
+#error You need at least flext version 0.4.6
#endif
#define PY__VERSION "0.1.3pre"
@@ -136,6 +136,8 @@ public:
V Unlock() {}
#endif
+ static PyObject* StdOut_Write(PyObject* Self, PyObject* Args);
+
protected:
// callbacks