1. Swig for Euphoria
- Posted by jeremy (admin) Mar 04, 2009
- 920 views
I was looking at Swig for Euphoria by David Cunny. An example is:
pow.i {{{ %{
- include <math.h> %}
double pow(double, double); }}
Then it creates a .c file and a .e file. The .c file is compiled to a .dll, and the .e wraps the .dll.
What is the reason for creating the .c and .dll file? I could see if this was a project written in C for the sole purpose of providing functionality to Euphoria, but most of the time we are wrapping other libraries, such as sqlite, iup, gtk, etc...
Jeremy
2. Re: Swig for Euphoria
- Posted by jeremy (admin) Mar 04, 2009
- 914 views
Wow, that example got goofed up. Let me try again:
%{ #include <math.h> %} double pow(double, double);
Hopefully this one works. I should learn to use the Preview
Jeremy
3. Re: Swig for Euphoria
- Posted by jimcbrown (admin) Mar 04, 2009
- 943 views
- Last edited Mar 05, 2009
I was looking at Swig for Euphoria by David Cunny.
What is the reason for creating the .c and .dll file? I could see if this was a project written in C for the sole purpose of providing functionality to Euphoria, but most of the time we are wrapping other libraries, such as sqlite, iup, gtk, etc...
Jeremy
Swig is designed to wrap C. One issue with wrapping C directly in Eu is because C symbols are mangled into funny looking symbols (in what may be an operating system dependant way, I'm not clear on this bit) in order to maintain compatibility with C and binary formats that expect C naming conventions. It gets worse when you try to access members, instantiate classes, etc.
Its very difficult to handle all of this directly from eu code (not impossible - just a lot of peeking and poking and similiar low level interfacing (e.g. vtable handling)) so the easier route is taken here: Let the native C/C compiler handle the details for us and just let the eu code see the nice little C functions that it is used to dealing with.
Swig is not the only one to have done this, btw: wxEuphoria used to interface to the wxWidgets library directly using a low level C interface written in eu but now it uses a C wrapper library.
4. Re: Swig for Euphoria
- Posted by mattlewis (admin) Mar 04, 2009
- 919 views
- Last edited Mar 05, 2009
Swig is designed to wrap C. One issue with wrapping C directly in Eu is because C symbols are mangled into funny looking symbols (in what may be an operating system dependant way, I'm not clear on this bit) in order to maintain compatibility with C and binary formats that expect C naming conventions. It gets worse when you try to access members, instantiate classes, etc.
It's worse than that. It's compiler dependent.
Swig is not the only one to have done this, btw: wxEuphoria used to interface to the wxWidgets library directly using a low level C interface written in eu but now it uses a C wrapper library.
Life is too short for that nonsense. It's well worth the hassle of having another binary file to distribute.
Matt
5. Re: Swig for Euphoria
- Posted by jeremy (admin) Mar 04, 2009
- 932 views
- Last edited Mar 05, 2009
Matt, why not use swig to wrap wxWidgets?
Jeremy
6. Re: Swig for Euphoria
- Posted by mattlewis (admin) Mar 05, 2009
- 938 views
Matt, why not use swig to wrap wxWidgets?
The C code of wxEuphoria does more than simply provide a C interface. It also converts data types (especially sequences to wxStrings). There are some things that are easier to do with C than with euphoria code when dealing with wxWidgets, and that's where the hand-written C comes in.
At one point, I did look at using Swig, but I couldn't figure out an easy way to get it to do what I wanted (I don't recall the details at this point).
Matt
7. Re: Swig for Euphoria
- Posted by ghaberek (admin) Mar 05, 2009
- 994 views
Matt, why not use swig to wrap wxWidgets?
The C code of wxEuphoria does more than simply provide a C interface. It also converts data types (especially sequences to wxStrings). There are some things that are easier to do with C than with euphoria code when dealing with wxWidgets, and that's where the hand-written C comes in.
At one point, I did look at using Swig, but I couldn't figure out an easy way to get it to do what I wanted (I don't recall the details at this point).
Also, wxWidgets (being C) is object-oriented, while Euphoria is not. wxEuphoria removes the "object-oriented-ness" from wxWidgets by abstracting it to regular functions and pointer-variables. I think this would be harder to do with SWIG, at least without ending up with a bunch of wxObjectName_FunctionName() type routines. There's quite a few all-in-one routines in wxEuphoria, like get/set_selection().
I may not be [much of] a C programmer, but I can certainly appreciate the hand-coded abstraction in wxEuphoria.
-Greg