From: <mes...@gm...> - 2011-11-13 16:06:21
|
consider the opposite problem: there is a struct t_foo * correctly wrapped with typemaps, and works correctly. now I'd like to call a Tcl proc from C, and passing a pointer to this struct as first argument. which facilities does SWIG provide to do this? for example, how to get the Tcl string representation of that pointer? after I get that, do I build my Tcl command as usual (for Tcl_EvalObjv() use), or is there some additional facility for calling scirpt procedures from C? thanks |
From: <mes...@gm...> - 2011-11-13 16:48:29
|
Il 13/11/2011 17:06, mes...@gm... ha scritto: > consider the opposite problem: > there is a struct t_foo * correctly wrapped with typemaps, and works > correctly. > now I'd like to call a Tcl proc from C, and passing a pointer to this > struct as first argument. > which facilities does SWIG provide to do this? > for example, how to get the Tcl string representation of that pointer? > after I get that, do I build my Tcl command as usual (for > Tcl_EvalObjv() use), or is there some additional facility for calling > scirpt procedures from C? > > thanks > apparently (looking at the generated output) I should use something like: Tcl_Obj *o = SWIG_Tcl_NewPointerObj((void *)mystructptr, SWIGTYPE_p_p__<typename>, 0); or the inner: char str[SWIG_BUFFER_SIZE]; SWIG_MakePtr(str, (void *)mystructptr, SWIGTYPE_p_p_<...>, 0); lokks like not the recommended way to do this... I'd have to manually pull out come declarations from the generated code any suggestion? I don't want to hide this struct fields under a typemap, so I didn't consider using typemaps this time |
From: Adam C. <ada...@ad...> - 2011-11-14 20:52:38
|
I have the same problem, and I used the same solution. Would love to hear the recommended way to do it. On 11/13/11 8:48 AM, "mes...@gm..." <mes...@gm...> wrote: >Il 13/11/2011 17:06, mes...@gm... ha scritto: >> consider the opposite problem: >> there is a struct t_foo * correctly wrapped with typemaps, and works >> correctly. >> now I'd like to call a Tcl proc from C, and passing a pointer to this >> struct as first argument. >> which facilities does SWIG provide to do this? >> for example, how to get the Tcl string representation of that pointer? >> after I get that, do I build my Tcl command as usual (for >> Tcl_EvalObjv() use), or is there some additional facility for calling >> scirpt procedures from C? >> >> thanks >> > >apparently (looking at the generated output) I should use something like: > >Tcl_Obj *o = SWIG_Tcl_NewPointerObj((void *)mystructptr, >SWIGTYPE_p_p__<typename>, 0); > >or the inner: > >char str[SWIG_BUFFER_SIZE]; >SWIG_MakePtr(str, (void *)mystructptr, SWIGTYPE_p_p_<...>, 0); > >lokks like not the recommended way to do this... I'd have to manually >pull out come declarations from the generated code >any suggestion? >I don't want to hide this struct fields under a typemap, so I didn't >consider using typemaps this time > >-------------------------------------------------------------------------- >---- >RSA(R) Conference 2012 >Save $700 by Nov 18 >Register now >http://p.sf.net/sfu/rsa-sfdev2dev1 >_______________________________________________ >Swig-user mailing list >Swi...@li... >https://lists.sourceforge.net/lists/listinfo/swig-user |
From: <mes...@gm...> - 2011-11-15 08:04:04
|
til now, the best I came up with, is having a typemap(in) for t_mystruct*, plus a C function: t_mystruct * CAST_t_mystruct(t_mystruct *s) { return s; } (very ugly to have to define those) so I have my own way of representing t_mystruct* as a string; but I still build my commands manually using the language (Tcl) C api On Mon, Nov 14, 2011 at 9:52 PM, Adam Cath <ada...@ad...> wrote: > I have the same problem, and I used the same solution. Would love to hear > the recommended way to do it. > > On 11/13/11 8:48 AM, "mes...@gm..." <mes...@gm...> wrote: > >>Il 13/11/2011 17:06, mes...@gm... ha scritto: >>> consider the opposite problem: >>> there is a struct t_foo * correctly wrapped with typemaps, and works >>> correctly. >>> now I'd like to call a Tcl proc from C, and passing a pointer to this >>> struct as first argument. >>> which facilities does SWIG provide to do this? >>> for example, how to get the Tcl string representation of that pointer? >>> after I get that, do I build my Tcl command as usual (for >>> Tcl_EvalObjv() use), or is there some additional facility for calling >>> scirpt procedures from C? >>> >>> thanks >>> >> >>apparently (looking at the generated output) I should use something like: >> >>Tcl_Obj *o = SWIG_Tcl_NewPointerObj((void *)mystructptr, >>SWIGTYPE_p_p__<typename>, 0); >> >>or the inner: >> >>char str[SWIG_BUFFER_SIZE]; >>SWIG_MakePtr(str, (void *)mystructptr, SWIGTYPE_p_p_<...>, 0); >> >>lokks like not the recommended way to do this... I'd have to manually >>pull out come declarations from the generated code >>any suggestion? >>I don't want to hide this struct fields under a typemap, so I didn't >>consider using typemaps this time >> >>-------------------------------------------------------------------------- >>---- >>RSA(R) Conference 2012 >>Save $700 by Nov 18 >>Register now >>http://p.sf.net/sfu/rsa-sfdev2dev1 >>_______________________________________________ >>Swig-user mailing list >>Swi...@li... >>https://lists.sourceforge.net/lists/listinfo/swig-user > > |
From: <mes...@gm...> - 2011-11-15 08:05:10
|
er... obviously using an additional typedef, to have multiple views of the same thing On Tue, Nov 15, 2011 at 9:03 AM, mes...@gm... <mes...@gm...> wrote: > til now, the best I came up with, is having a typemap(in) for > t_mystruct*, plus a C function: > > t_mystruct * CAST_t_mystruct(t_mystruct *s) { return s; } > > (very ugly to have to define those) > so I have my own way of representing t_mystruct* as a string; > but I still build my commands manually using the language (Tcl) C api > > On Mon, Nov 14, 2011 at 9:52 PM, Adam Cath <ada...@ad...> wrote: >> I have the same problem, and I used the same solution. Would love to hear >> the recommended way to do it. >> >> On 11/13/11 8:48 AM, "mes...@gm..." <mes...@gm...> wrote: >> >>>Il 13/11/2011 17:06, mes...@gm... ha scritto: >>>> consider the opposite problem: >>>> there is a struct t_foo * correctly wrapped with typemaps, and works >>>> correctly. >>>> now I'd like to call a Tcl proc from C, and passing a pointer to this >>>> struct as first argument. >>>> which facilities does SWIG provide to do this? >>>> for example, how to get the Tcl string representation of that pointer? >>>> after I get that, do I build my Tcl command as usual (for >>>> Tcl_EvalObjv() use), or is there some additional facility for calling >>>> scirpt procedures from C? >>>> >>>> thanks >>>> >>> >>>apparently (looking at the generated output) I should use something like: >>> >>>Tcl_Obj *o = SWIG_Tcl_NewPointerObj((void *)mystructptr, >>>SWIGTYPE_p_p__<typename>, 0); >>> >>>or the inner: >>> >>>char str[SWIG_BUFFER_SIZE]; >>>SWIG_MakePtr(str, (void *)mystructptr, SWIGTYPE_p_p_<...>, 0); >>> >>>lokks like not the recommended way to do this... I'd have to manually >>>pull out come declarations from the generated code >>>any suggestion? >>>I don't want to hide this struct fields under a typemap, so I didn't >>>consider using typemaps this time >>> >>>-------------------------------------------------------------------------- >>>---- >>>RSA(R) Conference 2012 >>>Save $700 by Nov 18 >>>Register now >>>http://p.sf.net/sfu/rsa-sfdev2dev1 >>>_______________________________________________ >>>Swig-user mailing list >>>Swi...@li... >>>https://lists.sourceforge.net/lists/listinfo/swig-user >> >> > |
From: Adam C. <ada...@ad...> - 2011-11-15 17:44:19
|
FWIW, here's what I've been doing for Lua. Not sure how it translates to TCL: In my .i file: %{ void swig_push_Apple(lua_State* L, Apple* obj) { SWIG_Lua_NewPointerObj(L, obj, SWIGTYPE_p_Apple, 0); // I get SWIGTYPE by running SWIG once and figuring out what name it generates } %} In my .cpp file: extern void swig_push_Apple(lua_State* L, Apple* obj); ... swig_push_Apple(L, new Apple()); Lua's C API is stack-based, so simply calling NewPointerObj (at the right time!) is sufficient to pass it as an argument. -Adam On 11/15/11 1:05 AM, "mes...@gm..." <mes...@gm...> wrote: >er... obviously using an additional typedef, to have multiple views of >the same thing > >On Tue, Nov 15, 2011 at 9:03 AM, mes...@gm... ><mes...@gm...> wrote: >> til now, the best I came up with, is having a typemap(in) for >> t_mystruct*, plus a C function: >> >> t_mystruct * CAST_t_mystruct(t_mystruct *s) { return s; } >> >> (very ugly to have to define those) >> so I have my own way of representing t_mystruct* as a string; >> but I still build my commands manually using the language (Tcl) C api >> >> On Mon, Nov 14, 2011 at 9:52 PM, Adam Cath <ada...@ad...> wrote: >>> I have the same problem, and I used the same solution. Would love to >>>hear >>> the recommended way to do it. >>> >>> On 11/13/11 8:48 AM, "mes...@gm..." <mes...@gm...> >>>wrote: >>> >>>>Il 13/11/2011 17:06, mes...@gm... ha scritto: >>>>> consider the opposite problem: >>>>> there is a struct t_foo * correctly wrapped with typemaps, and works >>>>> correctly. >>>>> now I'd like to call a Tcl proc from C, and passing a pointer to this >>>>> struct as first argument. >>>>> which facilities does SWIG provide to do this? >>>>> for example, how to get the Tcl string representation of that >>>>>pointer? >>>>> after I get that, do I build my Tcl command as usual (for >>>>> Tcl_EvalObjv() use), or is there some additional facility for calling >>>>> scirpt procedures from C? >>>>> >>>>> thanks >>>>> >>>> >>>>apparently (looking at the generated output) I should use something >>>>like: >>>> >>>>Tcl_Obj *o = SWIG_Tcl_NewPointerObj((void *)mystructptr, >>>>SWIGTYPE_p_p__<typename>, 0); >>>> >>>>or the inner: >>>> >>>>char str[SWIG_BUFFER_SIZE]; >>>>SWIG_MakePtr(str, (void *)mystructptr, SWIGTYPE_p_p_<...>, 0); >>>> >>>>lokks like not the recommended way to do this... I'd have to manually >>>>pull out come declarations from the generated code >>>>any suggestion? >>>>I don't want to hide this struct fields under a typemap, so I didn't >>>>consider using typemaps this time >>>> >>>>----------------------------------------------------------------------- >>>>--- >>>>---- >>>>RSA(R) Conference 2012 >>>>Save $700 by Nov 18 >>>>Register now >>>>http://p.sf.net/sfu/rsa-sfdev2dev1 >>>>_______________________________________________ >>>>Swig-user mailing list >>>>Swi...@li... >>>>https://lists.sourceforge.net/lists/listinfo/swig-user >>> >>> >> |
From: William S F. <ws...@fu...> - 2011-11-15 23:26:28
|
On 15/11/11 17:44, Adam Cath wrote: > FWIW, here's what I've been doing for Lua. Not sure how it translates to > TCL: > > In my .i file: > %{ > void swig_push_Apple(lua_State* L, Apple* obj) { > SWIG_Lua_NewPointerObj(L, obj, SWIGTYPE_p_Apple, 0); > // I get SWIGTYPE by running SWIG once and figuring out what name it > generates Use $1_descriptor or $descriptor(TYPE) to get the appropriate SWIGTYPE: http://www.swig.org/Doc2.0//Typemaps.html#Typemaps_special_macro_descriptor William |
From: Adam C. <ada...@ad...> - 2011-11-16 16:48:00
|
It's not a typemap, it's just inside %{ %}. I tried using $descriptor, and indeed, the macro didn't get expanded. -Adam On 11/15/11 3:26 PM, "William S Fulton" <ws...@fu...> wrote: >On 15/11/11 17:44, Adam Cath wrote: >> FWIW, here's what I've been doing for Lua. Not sure how it translates to >> TCL: >> >> In my .i file: >> %{ >> void swig_push_Apple(lua_State* L, Apple* obj) { >> SWIG_Lua_NewPointerObj(L, obj, SWIGTYPE_p_Apple, 0); >> // I get SWIGTYPE by running SWIG once and figuring out what name it >> generates > >Use $1_descriptor or $descriptor(TYPE) to get the appropriate SWIGTYPE: >http://www.swig.org/Doc2.0//Typemaps.html#Typemaps_special_macro_descripto >r > >William |
From: William S F. <ws...@fu...> - 2011-11-16 20:04:00
|
Oh okay, in that case you can use this: swig_type_info *info = SWIG_TypeQuery("Apple *"); const char *descriptor = info ? info->name : "Unknown type"; William On 16/11/11 16:47, Adam Cath wrote: > It's not a typemap, it's just inside %{ %}. I tried using $descriptor, and > indeed, the macro didn't get expanded. > > -Adam > > On 11/15/11 3:26 PM, "William S Fulton"<ws...@fu...> wrote: > >> On 15/11/11 17:44, Adam Cath wrote: >>> FWIW, here's what I've been doing for Lua. Not sure how it translates to >>> TCL: >>> >>> In my .i file: >>> %{ >>> void swig_push_Apple(lua_State* L, Apple* obj) { >>> SWIG_Lua_NewPointerObj(L, obj, SWIGTYPE_p_Apple, 0); >>> // I get SWIGTYPE by running SWIG once and figuring out what name it >>> generates >> >> Use $1_descriptor or $descriptor(TYPE) to get the appropriate SWIGTYPE: >> http://www.swig.org/Doc2.0//Typemaps.html#Typemaps_special_macro_descripto >> r >> >> William > > |
From: Adam C. <ada...@ad...> - 2011-11-16 20:35:18
|
Is that better? It seems slightly slower (since it does the lookup at runtime), but it uses the supported API. Is that why it's better? On 11/16/11 12:03 PM, "William S Fulton" <ws...@fu...> wrote: >Oh okay, in that case you can use this: > > swig_type_info *info = SWIG_TypeQuery("Apple *"); > const char *descriptor = info ? info->name : "Unknown type"; > >William > >On 16/11/11 16:47, Adam Cath wrote: >> It's not a typemap, it's just inside %{ %}. I tried using $descriptor, >>and >> indeed, the macro didn't get expanded. >> >> -Adam >> >> On 11/15/11 3:26 PM, "William S Fulton"<ws...@fu...> wrote: >> >>> On 15/11/11 17:44, Adam Cath wrote: >>>> FWIW, here's what I've been doing for Lua. Not sure how it translates >>>>to >>>> TCL: >>>> >>>> In my .i file: >>>> %{ >>>> void swig_push_Apple(lua_State* L, Apple* obj) { >>>> SWIG_Lua_NewPointerObj(L, obj, SWIGTYPE_p_Apple, 0); >>>> // I get SWIGTYPE by running SWIG once and figuring out what name it >>>> generates >>> >>> Use $1_descriptor or $descriptor(TYPE) to get the appropriate SWIGTYPE: >>> >>>http://www.swig.org/Doc2.0//Typemaps.html#Typemaps_special_macro_descrip >>>to >>> r >>> >>> William >> >> > |
From: William S F. <ws...@fu...> - 2011-11-25 21:44:38
|
Yes. Sometimes the mangling changes subtly especially when complex c++ types are used (template specialization and typedefs involving templates and the likes). William On 16/11/11 20:35, Adam Cath wrote: > Is that better? It seems slightly slower (since it does the lookup at > runtime), but it uses the supported API. Is that why it's better? > > On 11/16/11 12:03 PM, "William S Fulton"<ws...@fu...> wrote: > >> Oh okay, in that case you can use this: >> >> swig_type_info *info = SWIG_TypeQuery("Apple *"); >> const char *descriptor = info ? info->name : "Unknown type"; >> >> William >> >> On 16/11/11 16:47, Adam Cath wrote: >>> It's not a typemap, it's just inside %{ %}. I tried using $descriptor, >>> and >>> indeed, the macro didn't get expanded. >>> >>> -Adam >>> >>> On 11/15/11 3:26 PM, "William S Fulton"<ws...@fu...> wrote: >>> >>>> On 15/11/11 17:44, Adam Cath wrote: >>>>> FWIW, here's what I've been doing for Lua. Not sure how it translates >>>>> to >>>>> TCL: >>>>> >>>>> In my .i file: >>>>> %{ >>>>> void swig_push_Apple(lua_State* L, Apple* obj) { >>>>> SWIG_Lua_NewPointerObj(L, obj, SWIGTYPE_p_Apple, 0); >>>>> // I get SWIGTYPE by running SWIG once and figuring out what name it >>>>> generates >>>> >>>> Use $1_descriptor or $descriptor(TYPE) to get the appropriate SWIGTYPE: >>>> >>>> http://www.swig.org/Doc2.0//Typemaps.html#Typemaps_special_macro_descrip >>>> to >>>> r >>>> >>>> William >>> >>> >> > > |