• Call Custom C ++ library in TCL scripts

    From Lakshmi Ganesh@21:1/5 to All on Wed Apr 26 09:22:47 2023
    Hello All,

    I am relatively new to TCL, the topic I am exploring is that I would like to see whether we can call the methods from my custom c ++ library in TCL scripts. Is there any command available in TCL to call the method from external C ++ library. I am
    assuming this library has to be put along with the other TCL libraries.

    Any réponse is much appreciated.

    Thanks,
    Ganesh.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Lakshmi Ganesh on Wed Apr 26 17:31:24 2023
    Lakshmi Ganesh <lakshmiganesh.padmanaban@gmail.com> wrote:
    Hello All,

    I am relatively new to TCL, the topic I am exploring is that I would
    like to see whether we can call the methods from my custom c ++
    library in TCL scripts. Is there any command available in TCL to
    call the method from external C ++ library. I am assuming this
    library has to be put along with the other TCL libraries.

    Tcl does not have a native foreign function interface.

    The traditional way to do this is to write a small amount of C (or in
    your case C++) glue to provide that interface between scripts and C (or
    C++) functions.

    However, there is a FFI extension:

    https://wiki.tcl-lang.org/page/Ffidl

    The wiki page does say the last update was 2018, so your mileage may
    vary with it. The page also links to a couple other extensions.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lakshmi Ganesh@21:1/5 to Rich on Wed Apr 26 11:17:59 2023
    On Wednesday, April 26, 2023 at 12:31:29 PM UTC-5, Rich wrote:
    Lakshmi Ganesh <lakshmiganes...@gmail.com> wrote:
    Hello All,

    I am relatively new to TCL, the topic I am exploring is that I would
    like to see whether we can call the methods from my custom c ++
    library in TCL scripts. Is there any command available in TCL to
    call the method from external C ++ library. I am assuming this
    library has to be put along with the other TCL libraries.
    Tcl does not have a native foreign function interface.

    The traditional way to do this is to write a small amount of C (or in
    your case C++) glue to provide that interface between scripts and C (or
    C++) functions.

    However, there is a FFI extension:

    https://wiki.tcl-lang.org/page/Ffidl

    The wiki page does say the last update was 2018, so your mileage may
    vary with it. The page also links to a couple other extensions.


    Thank you very much for the pointer RIch !!!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From clt.to.davebr@dfgh.net@21:1/5 to All on Wed Apr 26 18:57:46 2023
    You might also take a look at some wiki pages:

    https://wiki.tcl-lang.org/page/Hello+World+as+a+C+extension

    https://wiki.tcl-lang.org/page/C%2B%2B+object%2Dstyle+Tcl+example+extension

    I learned the Tcl C API from Brent Welch's Practical Programming in TCL and TK The 4th edition is about 20 years old now, but it has a good write up on the C API.
    It is much better than trying to figure it out from the man pages.

    Others can probably recommend more recent books too.

    Dave B

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Gollwitzer@21:1/5 to All on Wed Apr 26 22:42:58 2023
    Am 26.04.23 um 18:22 schrieb Lakshmi Ganesh:
    I am relatively new to TCL, the topic I am exploring is that I would like to see whether we can call the methods from my custom c ++ library in TCL scripts. Is there any command available in TCL to call the method from external C ++ library. I am
    assuming this library has to be put along with the other TCL libraries.


    You can use SWIG to write the glue code for: https://www.swig.org/ SWIG
    can interface functions, classes, and (to some extent) templates.

    Christian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Heller@21:1/5 to Lakshmi Ganesh on Wed Apr 26 21:10:44 2023
    At Wed, 26 Apr 2023 11:17:59 -0700 (PDT) Lakshmi Ganesh <lakshmiganesh.padmanaban@gmail.com> wrote:


    On Wednesday, April 26, 2023 at 12:31:29 PM UTC-5, Rich wrote:
    Lakshmi Ganesh <lakshmiganes...@gmail.com> wrote:
    Hello All,

    I am relatively new to TCL, the topic I am exploring is that I would
    like to see whether we can call the methods from my custom c ++
    library in TCL scripts. Is there any command available in TCL to
    call the method from external C ++ library. I am assuming this
    library has to be put along with the other TCL libraries.
    Tcl does not have a native foreign function interface.

    The traditional way to do this is to write a small amount of C (or in
    your case C++) glue to provide that interface between scripts and C (or C++) functions.

    However, there is a FFI extension:

    https://wiki.tcl-lang.org/page/Ffidl

    The wiki page does say the last update was 2018, so your mileage may
    vary with it. The page also links to a couple other extensions.


    Thank you very much for the pointer RIch !!!

    There is a program called "SWIG" (Simplified Wrapper and Interface Generator), that can be "fed" a C or C++ header file and will generate a C or C++ source file that will provide the "glue" code.




    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jacob@21:1/5 to Lakshmi Ganesh on Wed Apr 26 15:21:11 2023
    On 4/26/2023 9:22 AM, Lakshmi Ganesh wrote:
    Hello All,

    I am relatively new to TCL, the topic I am exploring is that I would like to see whether we can call the methods from my custom c ++ library in TCL scripts. Is there any command available in TCL to call the method from external C ++ library. I am
    assuming this library has to be put along with the other TCL libraries.

    Any réponse is much appreciated.

    Thanks,
    Ganesh.

    I found Ashok's CFFI package to work well.

    https://cffi.magicsplat.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ashok@21:1/5 to Lakshmi Ganesh on Thu Apr 27 20:51:28 2023
    On 4/26/2023 9:52 PM, Lakshmi Ganesh wrote:
    Hello All,

    I am relatively new to TCL, the topic I am exploring is that I would like to see whether we can call the methods from my custom c ++ library in TCL scripts. Is there any command available in TCL to call the method from external C ++ library. I am
    assuming this library has to be put along with the other TCL libraries.

    Any réponse is much appreciated.

    Thanks,
    Ganesh.

    Does your library export a C++ API or a C API? Second, is the library a
    shared library or static?

    The ffidl/cffi solutions will only work well with shared libraries that
    export a C API.

    There is no standard C++ ABI (name mangling, parameter passing etc. all
    can differ between compilers and even versions of the same compiler). So
    if you are exporting a C++ API, then you will need to either write your
    own wrapper or use SWIG (compiling with the same compiler as your library.)

    /Ashok

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)