From 69118070c6c46b2c097b8b2e6fd0870c634b7114 Mon Sep 17 00:00:00 2001 From: mescalinum Date: Sun, 13 Sep 2009 15:50:31 +0000 Subject: added support for pd_bind/pd_unbind; added destructor call in tclpd_free svn path=/trunk/externals/tclpd/; revision=12330 --- tcl_class.cxx | 67 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 15 deletions(-) (limited to 'tcl_class.cxx') diff --git a/tcl_class.cxx b/tcl_class.cxx index 7525e77..81d5c98 100644 --- a/tcl_class.cxx +++ b/tcl_class.cxx @@ -70,22 +70,27 @@ t_tcl* tclpd_new(t_symbol* classsym, int ac, t_atom* at) { const char* name = classsym->s_name; t_class* qlass = class_table[string(name)]; - t_tcl* self = (t_tcl*)pd_new(qlass); - self->ninlets = 1 /* qlass->c_firstin ??? */; + t_tcl* x = (t_tcl*)pd_new(qlass); + x->ninlets = 1 /* qlass->c_firstin ??? */; + + x->classname = Tcl_NewStringObj(name, -1); + Tcl_IncrRefCount(x->classname); char s[64]; snprintf(s, 64, "tclpd:%s:x%lx", name, objectSequentialId++); - self->self = Tcl_NewStringObj(s, -1); - Tcl_IncrRefCount(self->self); + x->self = Tcl_NewStringObj(s, -1); + Tcl_IncrRefCount(x->self); + + x->x_glist = (t_glist*)canvas_getcurrent(); // store in object table (for later lookup) - object_table[string(s)] = (t_pd*)self; + object_table[string(s)] = (t_pd*)x; // build constructor command Tcl_Obj *av[ac+2]; InitArray(av, ac+2, NULL); - av[0] = Tcl_NewStringObj(name, -1); + av[0] = x->classname; Tcl_IncrRefCount(av[0]); - av[1] = self->self; + av[1] = x->self; Tcl_IncrRefCount(av[1]); for(int i=0; iself); +void tclpd_free(t_tcl* x) { + // build destructor command + Tcl_Obj *sym = Tcl_NewStringObj(Tcl_GetStringFromObj(x->classname, NULL), -1); + Tcl_AppendToObj(sym, "_destructor", -1); + Tcl_Obj *av[2]; InitArray(av, 2, NULL); + av[0] = sym; + Tcl_IncrRefCount(av[0]); + av[1] = x->self; + Tcl_IncrRefCount(av[1]); + // call destructor + if(Tcl_EvalObjv(tcl_for_pd, 2, av, 0) != TCL_OK) { +#ifdef DEBUG + post("tclpd_free: failed"); +#endif + } + Tcl_DecrRefCount(av[0]); + Tcl_DecrRefCount(av[1]); + + Tcl_DecrRefCount(x->self); + Tcl_DecrRefCount(x->classname); #ifdef DEBUG post("tclpd_free called"); #endif } -void tclpd_anything(t_tcl* self, t_symbol* s, int ac, t_atom* at) { - tclpd_inlet_anything(self, 0, s, ac, at); +void tclpd_anything(t_tcl* x, t_symbol* s, int ac, t_atom* at) { + tclpd_inlet_anything(x, 0, s, ac, at); } -void tclpd_inlet_anything(t_tcl* self, int inlet, t_symbol* s, int ac, t_atom* at) { +void tclpd_inlet_anything(t_tcl* x, int inlet, t_symbol* s, int ac, t_atom* at) { // proxy method - format: ... Tcl_Obj* av[ac+3]; InitArray(av, ac+3, NULL); int result; - av[0] = self->self; + av[0] = x->self; Tcl_IncrRefCount(av[0]); av[1] = Tcl_NewIntObj(inlet); Tcl_IncrRefCount(av[1]); @@ -179,6 +203,10 @@ t_tcl* tclpd_get_instance(const char* objectSequentialId) { return (t_tcl*)object_table[objectSequentialId]; } +t_pd* tclpd_get_instance_pd(const char* objectSequentialId) { + return (t_pd*)object_table[objectSequentialId]; +} + t_object* tclpd_get_object(const char* objectSequentialId) { t_tcl* x = tclpd_get_instance(objectSequentialId); return &x->o; @@ -189,6 +217,15 @@ t_pd* tclpd_get_object_pd(const char* objectSequentialId) { return &o->ob_pd; } +t_glist* tclpd_get_glist(const char* objectSequentialId) { + t_tcl* x = tclpd_get_instance(objectSequentialId); + return x->x_glist; +} + +t_symbol* null_symbol() { + return (t_symbol*)0; +} + void poststring2 (const char *s) { post("%s", s); } -- cgit v1.2.1