Wrap SDL_version
Leon Brocard [Tue, 3 Nov 2009 16:13:36 +0000 (16:13 +0000)]
Build.PL
lib/SDL/Version.pm [new file with mode: 0644]
src/Core/objects/Version.xs [new file with mode: 0644]
src/SDL.xs
t/core.t
t/core_version.t [new file with mode: 0644]
typemap

index 5124fe6..595c8da 100644 (file)
--- a/Build.PL
+++ b/Build.PL
@@ -114,6 +114,13 @@ my %subsystems =
                },
                libraries => [qw( SDL SDL_ttf )],
        },
+       Version => {
+               file      => {
+                       from  => 'src/Core/objects/Version.xs',
+                       to    => 'lib/SDL/Version.xs',
+               },
+               libraries => [qw( SDL )],
+       },
        OpenGL => {
                file      => {
                        from => 'src/OpenGL.xs',
diff --git a/lib/SDL/Version.pm b/lib/SDL/Version.pm
new file mode 100644 (file)
index 0000000..f6f7d2f
--- /dev/null
@@ -0,0 +1,9 @@
+package SDL::Version;
+use strict;
+use warnings;
+require Exporter;
+require DynaLoader;
+our @ISA = qw(Exporter DynaLoader);
+bootstrap SDL::Version;
+
+1;
diff --git a/src/Core/objects/Version.xs b/src/Core/objects/Version.xs
new file mode 100644 (file)
index 0000000..a6ef1ad
--- /dev/null
@@ -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
+
index 144f686..dff66d1 100644 (file)
@@ -308,6 +308,27 @@ was_init ( flags )
        OUTPUT:
                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
 delay ( ms )
        int ms
index 7b1e060..200d79f 100644 (file)
--- a/t/core.t
+++ b/t/core.t
@@ -39,9 +39,6 @@ my @left = qw/
        unload_fuction
        unload_object
        envvars
-       linked_version
-       version
-       Version
        /;
 
 my $why = '[Percentage Completion] '.int( 100 * $#done / ($#done + $#left) ) ."\% implementation. $#done / ".($#done+$#left); 
diff --git a/t/core_version.t b/t/core_version.t
new file mode 100644 (file)
index 0000000..15941c2
--- /dev/null
@@ -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' );
diff --git a/typemap b/typemap
index 369d2a5..b65aa5d 100644 (file)
--- a/typemap
+++ b/typemap
@@ -24,6 +24,7 @@ SDL_Color *           O_OBJECT
 SDL_Palette *          O_OBJECT
 SDL_PixelFormat *      O_OBJECT
 SDL_VideoInfo *                O_OBJECT
+SDL_version *          O_OBJECT
 SDL_Cursor *           T_PTR
 SDL_AudioSpec *                T_PTR
 SDL_AudioCVT *         T_PTR