diff options
author | mescalinum <mescalinum@users.sourceforge.net> | 2009-09-02 19:16:06 +0000 |
---|---|---|
committer | mescalinum <mescalinum@users.sourceforge.net> | 2009-09-02 19:16:06 +0000 |
commit | a1ced8f4ec6edcd66b03dd8584e037d701ca95e6 (patch) | |
tree | 1e4d3f7e19e41f722b29e7b2db52f0698daf8efd /tcl_class.cxx | |
parent | bf7fa9e9d5cf903cf95e9d99a364d93cb3b754d8 (diff) |
add support for save function (savefn)
svn path=/trunk/externals/tclpd/; revision=12190
Diffstat (limited to 'tcl_class.cxx')
-rw-r--r-- | tcl_class.cxx | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tcl_class.cxx b/tcl_class.cxx index 94c56ba..bd583a9 100644 --- a/tcl_class.cxx +++ b/tcl_class.cxx @@ -13,8 +13,12 @@ map<string,t_pd*> object_table; t_class* tclpd_class_new(const char* name, int flags) { t_class* c = class_new(gensym(name), (t_newmethod)tclpd_new, (t_method)tclpd_free, sizeof(t_tcl), flags, A_GIMME, A_NULL); + class_table[string(name)] = c; class_addanything(c, tclpd_anything); + + class_setsavefn(c, tclpd_save); + return c; } @@ -123,4 +127,51 @@ void poststring2 (const char *s) { } void tclpd_save(t_gobj* z, t_binbuf* b) { + Tcl_Obj* av[3], *res; + t_tcl* x = (t_tcl*)z; + av[0] = x->self; + av[1] = Tcl_NewStringObj("object", -1); + Tcl_IncrRefCount(av[1]); + av[2] = Tcl_NewStringObj("save", -1); + Tcl_IncrRefCount(av[2]); + int result = Tcl_EvalObjv(tcl_for_pd, 3, av, 0); + if(result == TCL_OK) { + res = Tcl_GetObjResult(tcl_for_pd); + Tcl_IncrRefCount(res); + int objc; + Tcl_Obj** objv; + result = Tcl_ListObjGetElements(tcl_for_pd, res, &objc, &objv); + if(result == TCL_OK) { + if(objc == 0 && objv == NULL) { + // call default savefn + text_save(z, b); + } else { + // do custom savefn + int i; + double tmp; + for(i = 0; i < objc; i++) { + result = Tcl_GetDoubleFromObj(tcl_for_pd, objv[i], &tmp); + if(result == TCL_OK) { + binbuf_addv(b, "f", (t_float)tmp); + } else { + char* tmps = Tcl_GetStringFromObj(objv[i], NULL); + if(!strcmp(tmps, ";")) { + binbuf_addv(b, ";"); + } else { + binbuf_addv(b, "s", gensym(tmps)); + } + } + } + } + } else { + pd_error(x, "Tcl: object save: failed"); + tclpd_interp_error(result); + } + Tcl_DecrRefCount(res); + } else { + pd_error(x, "Tcl: object save: failed"); + tclpd_interp_error(result); + } + Tcl_DecrRefCount(av[1]); + Tcl_DecrRefCount(av[2]); } |