enum define hooks

View: New views
3 Messages — Rating Filter:   Alert me  

enum define hooks

by Gour-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!

I'm on the verge of my 1st Haskell project where I want to use c2hs to
produce bindings for C library.

There are not (yet) "enum define" hooks implemented, so I wonder what's
convenient way to bind library with quite a lot of #defines like:

#define SE_SUN          0      
#define SE_MOON         1      
#define SE_MERCURY      2      
#define SE_VENUS        3      
#define SE_MARS         4      
#define SE_JUPITER      5      
#define SE_SATURN       6

and some in the form of:

#define SE_FNAME_DE200  "de200.eph"
#define SE_FNAME_DE403  "de403.eph"
#define SE_STARFILE     "fixstars.cat"


Sincerely,
Gour


_______________________________________________
C2hs mailing list
C2hs@...
http://www.haskell.org/mailman/listinfo/c2hs

attachment0 (202 bytes) Download Attachment

Re: enum define hooks

by Manuel M T Chakravarty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Gour:

> I'm on the verge of my 1st Haskell project where I want to use c2hs to
> produce bindings for C library.
>
> There are not (yet) "enum define" hooks implemented, so I wonder  
> what's
> convenient way to bind library with quite a lot of #defines like:
>
> #define SE_SUN          0
> #define SE_MOON         1
> #define SE_MERCURY      2
> #define SE_VENUS        3
> #define SE_MARS         4
> #define SE_JUPITER      5
> #define SE_SATURN       6
>
> and some in the form of:
>
> #define SE_FNAME_DE200  "de200.eph"
> #define SE_FNAME_DE403  "de403.eph"
> #define SE_STARFILE     "fixstars.cat"

I'd recommend to use inline C in the .chs file, where you define  
suitable enum with something like

   enum SE_ENUM {
     SE_ENUM_SUN = SE_SUN,
     <and so on>
   }

and then let c2hs marshal SE_ENUM.

Manuel

_______________________________________________
C2hs mailing list
C2hs@...
http://www.haskell.org/mailman/listinfo/c2hs

Re: enum define hooks

by Gour-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>>>>> "Manuel" == Manuel M T Chakravarty <chak@...> writes:

Hi Manuel,

Thank you for reply.

Manuel> I'd recommend to use inline C in the .chs file, where you define
Manuel> suitable enum with something like

Manuel>   enum SE_ENUM { SE_ENUM_SUN = SE_SUN, <and so on>
Manuel>   }

Manuel> and then let c2hs marshal SE_ENUM.

I was looking at examples and came up with the same solution:

#c
enum PlanetNumbers {
     SeSun = SE_SUN,
     ...
};
#endc

{#enum PlanetNumbers {}#}


It seems as very good workaround in the absence of "enum define" hooks.

Thank you for c2hs. I'm happy to use it...

Sincerely,
Gour

--

Gour  | Zagreb, Croatia  | GPG key: C6E7162D
----------------------------------------------------------------


_______________________________________________
C2hs mailing list
C2hs@...
http://www.haskell.org/mailman/listinfo/c2hs

attachment0 (202 bytes) Download Attachment
LightInTheBox - Buy quality products at wholesale price