diff options
-rw-r--r-- | tcl.i | 34 | ||||
-rw-r--r-- | tcl_class.c | 13 | ||||
-rw-r--r-- | tcl_extras.h | 12 | ||||
-rw-r--r-- | tcl_typemap.c | 30 |
4 files changed, 66 insertions, 23 deletions
@@ -54,9 +54,9 @@ %typemap(in) t_atom * { t_atom *a = (t_atom*)getbytes(sizeof(t_atom)); - if(tcl_to_pd($input, a) == TCL_ERROR) { + if(tcl_to_pdatom($input, a) == TCL_ERROR) { #ifdef DEBUG - post("Tcl SWIG: typemap(in) error"); + post("Tcl SWIG: typemap(in) [t_atom] error"); #endif return TCL_ERROR; } @@ -64,14 +64,36 @@ } %typemap(freearg) t_atom * { - freebytes($1, sizeof(t_atom)); + freebytes($input sizeof(t_atom)); } -%typemap(out) t_atom* { +%typemap(out) t_atom * { Tcl_Obj* res_obj; - if(pd_to_tcl($1, &res_obj) == TCL_ERROR) { + if(pdatom_to_tcl($input, &res_obj) == TCL_ERROR) { #ifdef DEBUG - post("Tcl SWIG: typemap(out) error"); + post("Tcl SWIG: typemap(out) [t_atom] error"); +#endif + return TCL_ERROR; + } + Tcl_SetObjResult(tcl_for_pd, res_obj); +} + +%typemap(in) t_symbol * { + t_symbol *s; + if(tcl_to_pdsymbol($input, &s) == TCL_ERROR) { +#ifdef DEBUG + post("Tcl SWIG: typemap(in) [t_symbol] error"); +#endif + return TCL_ERROR; + } + $1 = s; +} + +%typemap(out) t_symbol * { + Tcl_Obj* res_obj; + if(pdsymbol_to_tcl($input, &res_obj) == TCL_ERROR) { +#ifdef DEBUG + post("Tcl SWIG: typemap(out) [t_symbol] error"); #endif return TCL_ERROR; } diff --git a/tcl_class.c b/tcl_class.c index 596e28d..da8228f 100644 --- a/tcl_class.c +++ b/tcl_class.c @@ -118,12 +118,12 @@ t_tcl* tclpd_new(t_symbol* classsym, int ac, t_atom* at) { av[2] = Tcl_NewStringObj("constructor", -1); Tcl_IncrRefCount(av[2]); for(int i=0; i<ac; i++) { - // NOTE: pd_to_tcl already calls Tcl_IncrRefCount + // NOTE: pdatom_to_tcl already calls Tcl_IncrRefCount // so there is no need to call it here: - if(pd_to_tcl(&at[i], &av[3+i]) == TCL_ERROR) { + if(pdatom_to_tcl(&at[i], &av[3+i]) == TCL_ERROR) { #ifdef DEBUG - post("tclpd_new: failed conversion (pd_to_tcl)"); + post("tclpd_new: failed conversion (pdatom_to_tcl)"); #endif goto error; } @@ -201,9 +201,12 @@ void tclpd_inlet_anything(t_tcl* x, int inlet, t_symbol* s, int ac, t_atom* at) av[4] = Tcl_NewStringObj(s->s_name, -1); Tcl_IncrRefCount(av[4]); for(int i=0; i<ac; i++) { - if(pd_to_tcl(&at[i], &av[5+i]) == TCL_ERROR) { + // NOTE: pdatom_to_tcl already calls Tcl_IncrRefCount + // so there is no need to call it here: + + if(pdatom_to_tcl(&at[i], &av[5+i]) == TCL_ERROR) { #ifdef DEBUG - post("pd_to_tcl: tclpd_inlet_anything: failed during conversion. check memory leaks!"); + post("pdatom_to_tcl: tclpd_inlet_anything: failed during conversion. check memory leaks!"); #endif goto error; } diff --git a/tcl_extras.h b/tcl_extras.h index 283816d..f09a7ba 100644 --- a/tcl_extras.h +++ b/tcl_extras.h @@ -50,11 +50,13 @@ void proxyinlet_setup(void); extern int Tclpd_SafeInit(Tcl_Interp *interp); /* tcl_typemap.c */ -int pd_to_tcl(t_atom* input, Tcl_Obj** output); -int tcl_to_pd(Tcl_Obj* input, t_atom* output); -const char* atom_type_string(t_atom* a); -const char* atom_symbol_value(t_atom* a); -float atom_float_value(t_atom* a); +int tcl_to_pdatom(Tcl_Obj *input, t_atom *output); +int tcl_to_pdsymbol(Tcl_Obj *input, t_symbol **output); +const char* pdatom_type_string(t_atom* a); +const char* pdatom_symbol_value(t_atom* a); +float pdatom_float_value(t_atom* a); +int pdatom_to_tcl(t_atom *input, Tcl_Obj **output); +int pdsymbol_to_tcl(t_symbol *input, Tcl_Obj **output); /* tclpd.c */ extern Tcl_Interp* tcl_for_pd; diff --git a/tcl_typemap.c b/tcl_typemap.c index 65f3872..3671025 100644 --- a/tcl_typemap.c +++ b/tcl_typemap.c @@ -1,7 +1,7 @@ #include "tcl_extras.h" #include <string.h> -int tcl_to_pd(Tcl_Obj *input, t_atom *output) { +int tcl_to_pdatom(Tcl_Obj *input, t_atom *output) { int llength; if(Tcl_ListObjLength(tcl_for_pd, input, &llength) == TCL_ERROR) return TCL_ERROR; @@ -28,7 +28,13 @@ int tcl_to_pd(Tcl_Obj *input, t_atom *output) { return TCL_OK; } -const char* atom_type_string(t_atom* a) { +int tcl_to_pdsymbol(Tcl_Obj *input, t_symbol **output) { + char* s = Tcl_GetStringFromObj(input, 0); + *output = gensym(s); + return TCL_OK; +} + +const char* pdatom_type_string(t_atom* a) { switch(a->a_type) { case A_FLOAT: case A_DEFFLOAT: @@ -48,7 +54,7 @@ const char* atom_type_string(t_atom* a) { } } -const char* atom_symbol_value(t_atom* a) { +const char* pdatom_symbol_value(t_atom* a) { if(a->a_type == A_DOLLAR) { char buf[6]; snprintf(buf, 6, "$%d", a->a_w.w_index); @@ -58,14 +64,14 @@ const char* atom_symbol_value(t_atom* a) { return a->a_w.w_symbol->s_name; } -float atom_float_value(t_atom* a) { +float pdatom_float_value(t_atom* a) { return a->a_w.w_float; } -int pd_to_tcl(t_atom *input, Tcl_Obj **output) { +int pdatom_to_tcl(t_atom *input, Tcl_Obj **output) { Tcl_Obj* tcl_t_atom[2]; #ifdef DEBUG - post("pd_to_tcl: atom type = %d (%s)", + post("pdatom_to_tcl: atom type = %d (%s)", input->a_type, input->a_type == A_FLOAT ? "A_FLOAT" : input->a_type == A_SYMBOL ? "A_SYMBOL" : input->a_type == A_POINTER ? "A_POINTER" : "?"); @@ -94,9 +100,19 @@ int pd_to_tcl(t_atom *input, Tcl_Obj **output) { } } #ifdef DEBUG - post("pd_to_tcl: atom value = \"%s\"", Tcl_GetStringFromObj(tcl_t_atom[1], 0)); + post("pdatom_to_tcl: atom value = \"%s\"", Tcl_GetStringFromObj(tcl_t_atom[1], 0)); #endif *output = Tcl_NewListObj(2, &tcl_t_atom[0]); Tcl_IncrRefCount(*output); return TCL_OK; } + +int pdsymbol_to_tcl(t_symbol *input, Tcl_Obj **output) { + Tcl_Obj* s[2]; + s[0] = Tcl_NewStringObj("symbol", -1); + s[1] = Tcl_NewStringObj(input->s_name, -1); + *output = Tcl_NewListObj(2, &s[0]); + Tcl_IncrRefCount(*output); + return TCL_OK; +} + |