Skip to content

Commit

Permalink
Wrap SDL_version
Browse files Browse the repository at this point in the history
  • Loading branch information
acme committed Nov 3, 2009
1 parent bfb478a commit ce88b52
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Build.PL
Expand Up @@ -114,6 +114,13 @@ my %subsystems =
}, },
libraries => [qw( SDL SDL_ttf )], libraries => [qw( SDL SDL_ttf )],
}, },
Version => {
file => {
from => 'src/Core/objects/Version.xs',
to => 'lib/SDL/Version.xs',
},
libraries => [qw( SDL )],
},
OpenGL => { OpenGL => {
file => { file => {
from => 'src/OpenGL.xs', from => 'src/OpenGL.xs',
Expand Down
9 changes: 9 additions & 0 deletions lib/SDL/Version.pm
@@ -0,0 +1,9 @@
package SDL::Version;
use strict;
use warnings;
require Exporter;
require DynaLoader;
our @ISA = qw(Exporter DynaLoader);
bootstrap SDL::Version;

1;
49 changes: 49 additions & 0 deletions src/Core/objects/Version.xs
@@ -0,0 +1,49 @@
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#ifndef aTHX_
#define aTHX_
#endif

#include <SDL.h>
#include <SDL_version.h>

MODULE = SDL::Version PACKAGE = SDL::Version PREFIX = version_

=for documentation

SDL_Version -- Version structure

typedef struct SDL_version {
Uint8 major;
Uint8 minor;
Uint8 patch;
} SDL_version;

=cut

Uint8
version_major ( version, ... )
SDL_version *version
CODE:
RETVAL = version->major;
OUTPUT:
RETVAL

Uint8
version_minor ( version, ... )
SDL_version *version
CODE:
RETVAL = version->minor;
OUTPUT:
RETVAL

Uint8
version_patch ( version, ... )
SDL_version *version
CODE:
RETVAL = version->patch;
OUTPUT:
RETVAL

21 changes: 21 additions & 0 deletions src/SDL.xs
Expand Up @@ -308,6 +308,27 @@ was_init ( flags )
OUTPUT: OUTPUT:
RETVAL RETVAL


SDL_version *
version ()
PREINIT:
char * CLASS = "SDL::Version";
SDL_version *version;
CODE:
version = (SDL_version *) safemalloc (sizeof(SDL_version));
SDL_VERSION(version);
RETVAL = version;
OUTPUT:
RETVAL

SDL_version *
linked_version ()
PREINIT:
char * CLASS = "SDL::Version";
CODE:
RETVAL = (SDL_version *) SDL_Linked_Version();
OUTPUT:
RETVAL

void void
delay ( ms ) delay ( ms )
int ms int ms
Expand Down
3 changes: 0 additions & 3 deletions t/core.t
Expand Up @@ -39,9 +39,6 @@ my @left = qw/
unload_fuction unload_fuction
unload_object unload_object
envvars envvars
linked_version
version
Version
/; /;


my $why = '[Percentage Completion] '.int( 100 * $#done / ($#done + $#left) ) ."\% implementation. $#done / ".($#done+$#left); my $why = '[Percentage Completion] '.int( 100 * $#done / ($#done + $#left) ) ."\% implementation. $#done / ".($#done+$#left);
Expand Down
20 changes: 20 additions & 0 deletions t/core_version.t
@@ -0,0 +1,20 @@
#!/usr/bin/perl -w
use strict;
use SDL;
use SDL::Version;
use Test::More tests => 8;

my $version = SDL::version();
isa_ok( $version, 'SDL::Version' );
like( $version->major, qr/^\d+$/, 'Compile-time version major is a number' );
like( $version->minor, qr/^\d+$/, 'Compile-time version minor is a number' );
like( $version->patch, qr/^\d+$/, 'Compile-time version patch is a number' );

my $linked_version = SDL::linked_version();
isa_ok( $linked_version, 'SDL::Version' );
like( $linked_version->major, qr/^\d+$/,
'Link-time version major is a number' );
like( $linked_version->minor, qr/^\d+$/,
'Link-time version minor is a number' );
like( $linked_version->patch, qr/^\d+$/,
'Link-time version patch is a number' );
1 change: 1 addition & 0 deletions typemap
Expand Up @@ -24,6 +24,7 @@ SDL_Color * O_OBJECT
SDL_Palette * O_OBJECT SDL_Palette * O_OBJECT
SDL_PixelFormat * O_OBJECT SDL_PixelFormat * O_OBJECT
SDL_VideoInfo * O_OBJECT SDL_VideoInfo * O_OBJECT
SDL_version * O_OBJECT
SDL_Cursor * T_PTR SDL_Cursor * T_PTR
SDL_AudioSpec * T_PTR SDL_AudioSpec * T_PTR
SDL_AudioCVT * T_PTR SDL_AudioCVT * T_PTR
Expand Down

0 comments on commit ce88b52

Please sign in to comment.