s> Replacing main doesn’t work. My code is in a DLL
That’s fine, just don’t expect your code to work on every platform.
It isn’t my code, but code written by clients of my system.
At the moment, except as examples to others, I’m not
writing SDL apps – I’m trying to build bindings to the SDL library,
and organise that if SDL is installed on your computer …
it ‘just works’ with Felix, out of the box, on any platform.
BTW: I do plan to use SDL to write games, but I want to
make some decent ones and that just can’t be done in weak
languages like C. So I’ve developed a whole new programming
language, just to write games with!
You will break on BeOS, MacOS, and if your user tries to use
DirectInput, you will break on Windows too (note the
SDL_SetModuleHandle(GetModuleHandle(NULL)) in the win32 startup).
Noted. That one is a bug! MSDN says:
“If this parameter is NULL, GetModuleHandle returns a handle to the file
used to create the calling process (.exe file).”
Which means there is no reason not to make that call in SDL_init.
Or even any time you need the module handle.
If you understand these risks and accept them, I guess it’s fine, but
you shouldn’t tell new users trying to get started with the library to
bypass this.
I agree. Instead I asked Sam if it were possible
to fix this problem in SDL 1.3. It’s a pain for many people,
newbies and others alike.
Since main only gets called once, it is usually
possible to replace that hack with
T *x = SDL_statup(argc, argv);
// mainline code here
SDL_finish(x);
where the code in SDL_startup and SDL_finish is exactly
what SDL’s main does now – startup does what would be
done just before SDL_main() is called, and SDL_finish(x)
is done after SDL_main() is called, and T is some struct
containing any state that would otherwise have been
preserved on the stack.
The ONLY thing you cannot do this way is something demanding
the stack such as setjmp/longjmp and I wouldn’t allow
one of them on top of my mainline anyhow.
If this were done, there would be two ways to use SDL:
the simple way, with main replacement, and the slightly
harder way, using SDL_startup/SDL_finish.
Frankly, I’d scrub the “simpler” way because it’s seriously non-portable
and hard to support, and is actually harder for newbies
to use, since it requires arcane knowledge of linker
and compiler switches, and/or sdl-config to be present
and work correctly. In other words, its actually harder
to use than the startup/finish paradigm, which is more
general and better engineering.
Well I don’t expect anyone to break compatibility
by srubbing the existing main replacement paradigm!
Please provide the startup/finish paradigm as well!
The former is easily defined given the latter,
but not vice versa.
It’s quite clear looking at the main code and comments
this is intended anyhow: comments indicate code has
been migrated out into SDL_init.
I’m just hoping this will be done in SDL 1.3.
Without it, embeddding – which most if not all language
bindings need – will be much more difficult. Whoever
maintains the Ocaml, Python, Perl … or Felix bindings
has to do a lot less work with the startup/finish paradigm
than a main replacement paradigm for the simple reason
the latter is unusable. You really don’t think Perl
or Python would defer to SDL and allow it to replace
its mainline? They too will require any startup/finish
code to be called from dynamically loaded shared libraries,
as does Felix.On Sun, 2006-03-05 at 01:03 +0000, Peter Mulholland wrote:
–
John Skaller
Async PL, Realtime software consultants
Checkout Felix: http://felix.sourceforge.net