From b961106236fb569dd7b840e90a47c534bd3b179c Mon Sep 17 00:00:00 2001 From: mescalinum Date: Fri, 11 Nov 2011 09:13:54 +0000 Subject: add typemap for t_symbol* (but does not work for return values, like in canvas_getdir()) svn path=/trunk/externals/loaders/tclpd/; revision=15722 --- tcl.i | 34 ++++++++++++++++++++++++++++------ tcl_class.c | 13 ++++++++----- tcl_extras.h | 12 +++++++----- tcl_typemap.c | 30 +++++++++++++++++++++++------- 4 files changed, 66 insertions(+), 23 deletions(-) diff --git a/tcl.i b/tcl.i index 6a02761..234e9e1 100644 --- a/tcl.i +++ b/tcl.i @@ -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; is_name, -1); Tcl_IncrRefCount(av[4]); for(int i=0; i -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; +} + -- cgit v1.2.1