caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Erkki Seppala <flux-caml@inside.org>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] SDL2 bindings, testers and feedback welcome
Date: Tue, 17 Dec 2013 21:29:35 +0200	[thread overview]
Message-ID: <m4961qnmg2o.fsf@coffee.modeemi.fi> (raw)
In-Reply-To: <1C9496037B6149EC970D65C3BFA490F7@erratique.ch> ("Daniel =?utf-8?Q?B=C3=BCnzli=22's?= message of "Tue, 17 Dec 2013 18:47:42 +0100")

Daniel Bünzli <daniel.buenzli@erratique.ch> writes:

> However I think this discussion is mostly irrelevant here
> since we are constrained by the loose design of the underlying library
> which, as I said, doesn't differentiate/document enough its errors and
> provides them only as strings. So what I did is to return `Error
> whenever the function may return an error and the documentation
> indicates that Sdl.get_error () can be used to get more information
> (they don't expose error codes).

Amazing! I checked SDL2 out and indeed, the only way to do reporting is
with SDL_SetError(const char *fmt, ...);. I imagine it must be a great
easy way to make simple error reporting, but it sure doesn't make it
easy to handle them.

Here is an overly-complicated and slightly unrealistic solution:

- Find each error from the code automatically

Examples:
  SDL_SetError("SDL not built with video support");
  SDL_SetError("Couldn't open %s", filename);

- Transform them into:
type error = [ `SDL_not_build_with_video_support
             | `Couldnt_open of string ]

- And maybe:
exception SDL_Error of error

With some code analysis one could even discover what errors are thrown
by which functions :-o. (Actually without that the previous mapping
without exceptions wouldn't be very useful.)

This scheme of course fails with

  SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "",
  message);

which would need manual handling.

So perhaps it's not realistic, not worth the trouble and not aligned
with your goals of making a very thin wrapping layer. Maybe this kind of
'safer' layer could be built as an additional layer over Tsdl.

But I think a small enhancement would be making the error an `Error of
string. It would make the stringly typed error handling of SDL more
apparent to the user and give more direct suggestion on how to deal with
them.

> Thin (bindings to) SDL. I could have used Sdl but I don't like to take ownership of toplevel names that are used in other settings.

I think the name might make one think the bindings are for
libsdl1. Would Tsdl2 be too verbose?

Thanks for great work! I'm sure to check the bindings out in practice
the next time I find myself needing to deal with the task SDL is
suitable for :).

-- 
  _____________________________________________________________________
     / __// /__ ____  __               http://www.modeemi.fi/~flux/\   \
    / /_ / // // /\ \/ /                                            \  /
   /_/  /_/ \___/ /_/\_\@modeemi.fi                                  \/

  parent reply	other threads:[~2013-12-17 19:29 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-17  6:11 Daniel Bünzli
2013-12-17  7:02 ` Anthony Tavener
2013-12-17 14:17 ` Florent Monnier
2013-12-17 15:14   ` Daniel Bünzli
2013-12-18  6:54   ` Erkki Seppala
2013-12-18  8:05     ` Anthony Tavener
2013-12-18  9:24       ` Daniel Bünzli
2013-12-18  8:18     ` Florent Monnier
2013-12-22 10:01       ` Kakadu
2013-12-30 13:28         ` Vu Ngoc San
2013-12-17 17:05 ` Ashish Agarwal
2013-12-17 17:47   ` Daniel Bünzli
2013-12-17 18:57     ` Ashish Agarwal
2013-12-17 19:45       ` Anthony Tavener
2013-12-18 15:40         ` Ashish Agarwal
2013-12-18 18:02           ` Yotam Barnoy
2013-12-18 19:53             ` Daniel Bünzli
2013-12-18 22:29               ` Ashish Agarwal
2013-12-18 22:45                 ` Daniel Bünzli
2013-12-17 20:26       ` Daniel Bünzli
2013-12-18  1:13         ` Francois Berenger
2013-12-18  6:44           ` Erkki Seppala
2013-12-18  9:21           ` Daniel Bünzli
2013-12-19  1:11             ` Florent Monnier
2013-12-19  6:39       ` Florent Monnier
2013-12-17 19:29     ` Erkki Seppala [this message]
2013-12-19  5:20 ` Florent Monnier
2013-12-19  5:27   ` Florent Monnier
2013-12-19  7:13   ` Daniel Bünzli
2013-12-19 12:38     ` Florent Monnier
2014-02-12 10:43 ` Daniel Bünzli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m4961qnmg2o.fsf@coffee.modeemi.fi \
    --to=flux-caml@inside.org \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).