[m-users.] FFI C Include files not appearing
emacstheviking
objitsu at gmail.com
Tue Jun 25 20:56:17 AEST 2019
Hi Peter,
I did wonder about that ...you can tell I am new to mercury for sure. My
plan is to create as simple an interface to SDL2 as possible. I produced a
full wrapper for GNU Prolog and it took ages...this time the "plan" is to
produce something akin to a "display list" (my Atari days!) and then have a
single C function that walks the display list and turns each entry into the
appropriate SDL draw line, point, image etc etc
Can you explain why I need to pass in !IO if I am not actually going to
modify it? I am a bit confused about the
sdl_up(Result::out, _IO0::di, _IO::uo)
Or is this something that the compiler will be making use of...like I say,
I am new to mercury but I am pretty familiar with Haskell and Prolog if
that helps to explain anything.
I will need some extra support for fonts and textures but that's the fun of
exploratory hacking!
Thanks again,
Sean.
On Tue, 25 Jun 2019 at 11:42, Peter Wang <novalazy at gmail.com> wrote:
> On Tue, 25 Jun 2019 11:03:53 +0100, emacstheviking <objitsu at gmail.com>
> wrote:
> > Hi,
> > I have these two lines of code...
> >
> > :- pragma foreign_decl("C", "#include <SDL/SDL.h>").
> > :- pragma foreign_decl("C", "#include <SDL/SDL_version.h>").
> >
> > at the top of my module in the implementation section and this code too:
> > :- func sdl_up = int.
> > :- pragma foreign_proc("C",
> > sdl_up = (Result::out),
> > [ will_not_call_mercury
> > , not_thread_safe
> > , promise_pure
> > ],
> > "Result = SDL_Init(SDL_INIT_EVERYTHING);").
> >
>
> Hi,
>
> SDL_Init() is impure, so wrapping it up in pure function is incorrect.
> Rather, you should wrap it in a predicate that takes the I/O state:
>
> :- pred sdl_up(int::out, io::di, io::uo) is det.
>
> :- pragma foreign_proc("C",
> sdl_up(Result::out, _IO0::di, _IO::uo),
> [will_not_call_mercury, promise_pure],
> "
> Result = SDL_Init(SDL_INIT_EVERYTHING);
> ").
>
> Peter
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20190625/f4a72b68/attachment-0001.html>
More information about the users
mailing list