[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Wrapping C functions

From: David Chisnall
Subject: Re: Wrapping C functions
Date: Thu, 6 Aug 2009 17:53:58 +0100

On 6 Aug 2009, at 17:48, Martin Kalbfuß wrote:

Some functions belong clearly to an object, like the bitmap functions for example. But I don't know whhere to put functions like SDL_init. Should I
create a library object or system object or something?

The best place for things like this is inside a +initialize method. On some object wrapping global SDL state, add this method:

+ (void)initialize
        // Protect from calls by subclass
        if (self != [SDLState class]) return;

        // Any other library initialization that you need.

This method will be called exactly once the first time the SDLState class receives. In order to instantiate the class, you send it an +alloc (or similar) message, so this will be called before the first time you create an instance of the class.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]