[mercury-users] Working with exported types
Peter Wang
wangp at students.csse.unimelb.edu.au
Thu Jul 27 16:51:09 AEST 2006
On 2006-07-27, Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
>
> On Thu, 27 Jul 2006, Peter Wang wrote:
>
> >On 2006-07-27, Ralph Becket <rafe at csse.unimelb.edu.au> wrote:
> >>Julien Fischer, Thursday, 27 July 2006:
> >>>Another approach that I have thought about adding (because doing the
> >>>above
> >>>in the OpenGL binding was fairly tedious), is to add a foreign_enum
> >>>pragma
> >>>that would allow you to safely use the values of Mercury enums on the
> >>>other
> >>>side of the foreign language interface, something like:
> >>>
> >>> :- type foo
> >>> ---> foo
> >>> ; bar
> >>> ; baz
> >>>
> >>> :- pragma foreign_enum("C", [
> >>> foo - "FOO",
> >>> bar - "BAR",
> >>> baz - "BAZ"]).
> >>>
> >>>The compiler would then add the following to the modules .mh file:
> >>>
> >>> #define FOO <representation of foo>
> >>> #define BAR <representation of bar>
> >>> #define BAZ (representation of baz>
> >>
> >>This would be an excellent addition to the FLI.
> >
> >Can we get something in the opposite direction as well?
>
> What exactly do you mean? The above also handles the opposite direction.
Does it? I'm interested in importing C constants *into* Mercury,
without going through the contortions you've gone through in the OpenGL
binding. At the moment the easiest way to do that is to hard-code the
value into the Mercury code, but that's brittle. The second easiest way
is probably to introduce a foreign proc for each C constant, but that's
tedious.
Peter
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list