1. Swig for Euphoria

I was looking at Swig for Euphoria by David Cunny. An example is:

pow.i {{{ %{

  1. 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

new topic     » topic index » view message » categorize

2. Re: Swig for Euphoria

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 grin

Jeremy

new topic     » goto parent     » topic index » view message » categorize

3. Re: Swig for Euphoria

jeremy said...

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.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Swig for Euphoria

jimcbrown said...

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.

jimcbrown said...

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

new topic     » goto parent     » topic index » view message » categorize

5. Re: Swig for Euphoria

Matt, why not use swig to wrap wxWidgets?

Jeremy

new topic     » goto parent     » topic index » view message » categorize

6. Re: Swig for Euphoria

jeremy said...

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

new topic     » goto parent     » topic index » view message » categorize

7. Re: Swig for Euphoria

mattlewis said...
jeremy said...

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. blink

-Greg

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu