aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--error-help.pd35
-rw-r--r--error.c78
3 files changed, 114 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 7862ca9..cb801f8 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ LIBRARY_NAME = log
# add your .c source files, one object per file, to the SOURCES
# variable, help files will be included automatically, and for GUI
# objects, the matching .tcl file too
-SOURCES = logpost.c
+SOURCES = logpost.c error.c
# list all pd objects (i.e. myobject.pd) files here, and their helpfiles will
# be included automatically
diff --git a/error-help.pd b/error-help.pd
new file mode 100644
index 0000000..d55b958
--- /dev/null
+++ b/error-help.pd
@@ -0,0 +1,35 @@
+#N canvas 545 156 511 332 10;
+#X obj 49 38 hsl 128 15 0 127 0 0 empty empty empty -2 -8 0 10 -262144
+-1 -1 0 1;
+#X msg 47 120 symbol hello;
+#X msg 61 143 hello;
+#X text 22 7 post at different levels;
+#X obj 224 137 hsl 128 15 0 127 0 0 empty empty empty -2 -8 0 10 -262144
+-1 -1 3100 1;
+#X obj 46 81 error;
+#X obj 53 289 error;
+#X obj 221 157 error this ia long box of test;
+#X msg 69 168 what is in here;
+#X msg 89 192 list this is a test;
+#X msg 90 226 list 1 2 3;
+#X msg 93 248 1 2 3;
+#X obj 285 55 pointer;
+#X msg 282 23 bang;
+#X obj 286 86 error;
+#X obj 255 287 error;
+#X msg 275 264 list;
+#X msg 275 242 list 1;
+#X msg 258 221 list word;
+#X connect 0 0 5 0;
+#X connect 1 0 6 0;
+#X connect 2 0 6 0;
+#X connect 4 0 7 0;
+#X connect 8 0 6 0;
+#X connect 9 0 6 0;
+#X connect 10 0 6 0;
+#X connect 11 0 6 0;
+#X connect 12 0 14 0;
+#X connect 13 0 12 0;
+#X connect 16 0 15 0;
+#X connect 17 0 15 0;
+#X connect 18 0 15 0;
diff --git a/error.c b/error.c
new file mode 100644
index 0000000..bdca131
--- /dev/null
+++ b/error.c
@@ -0,0 +1,78 @@
+
+#include "m_pd.h"
+
+static t_class *error_class;
+
+typedef struct _error
+{
+ t_object x_obj;
+ int level;
+ t_symbol* tag;
+} t_error;
+
+static t_symbol* args2symbol(int argc, t_atom *argv)
+{
+ t_symbol* s;
+ char* buf;
+ int bufsize;
+ t_binbuf *bb = binbuf_new();
+ binbuf_add(bb, argc, argv);
+ binbuf_gettext(bb, &buf, &bufsize);
+ buf = resizebytes(buf, bufsize, bufsize+1);
+ buf[bufsize] = 0;
+ s = gensym(buf);
+ freebytes(buf, bufsize+1);
+ binbuf_free(bb);
+ return s;
+}
+
+static void error_bang(t_error *x)
+{
+ logpost(x, x->level, "%s%sbang",
+ x->tag->s_name, (*x->tag->s_name ? ": " : ""));
+}
+
+static void error_pointer(t_error *x, t_gpointer *gp)
+{
+ logpost(x, x->level, "%s%s(pointer %lx)",
+ x->tag->s_name, (*x->tag->s_name ? ": " : ""), gp);
+}
+
+static void error_float(t_error *x, t_float f)
+{
+ logpost(x, (const int)x->level, "%s%s%g",
+ x->tag->s_name, (*x->tag->s_name ? ": " : ""), f);
+}
+
+static void error_anything(t_error *x, t_symbol *s, int argc, t_atom *argv)
+{
+ post("error_anything %s", s->s_name);
+ t_symbol* output = args2symbol(argc, argv);
+ logpost(x, (const int)x->level, "%s%s%s %s",
+ x->tag->s_name, (*x->tag->s_name ? ": " : ""),
+ s->s_name, output->s_name);
+}
+
+static void *error_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_error *x = (t_error *)pd_new(error_class);
+ x->tag = &s_;
+ x->level = 1;
+ if (argc > 0)
+ x->tag = args2symbol(argc, argv);
+ return (x);
+}
+
+void error_setup(void)
+{
+ error_class = class_new(gensym("error"),
+ (t_newmethod)error_new,
+ 0,
+ sizeof(t_error),
+ CLASS_DEFAULT,
+ A_GIMME, 0);
+ class_addbang(error_class, error_bang);
+ class_addfloat(error_class, error_float);
+ class_addpointer(error_class, error_pointer);
+ class_addanything(error_class, error_anything);
+}