Wrote a really shotty callback need someone to review it. Need to devise testplan...
Kartik Thakore [Thu, 12 Nov 2009 02:37:51 +0000 (21:37 -0500)]
src/Core/Events.xs
t/core_events.t

index 090ae6c..3451610 100644 (file)
@@ -9,6 +9,43 @@
 #include <SDL.h>
 #include <SDL_events.h>
 
+/* Static Memory for event filter call back */
+static SV * eventfiltersv;
+
+
+int eventfilter_cb( const void * event)
+{
+
+       dSP;
+       int count;
+       int filter_signal;
+
+       ENTER;
+       SAVETMPS;
+       PUSHMARK(SP);
+
+       XPUSHs((SDL_Event *)event);
+
+       PUTBACK;
+       
+       filter_signal = call_sv(eventfiltersv, G_SCALAR);
+
+       SPAGAIN;
+
+       if (count != 1 ) croak("callback returned more than 1 value\n");
+       
+       filter_signal = POPi;
+
+       FREETMPS;
+       LEAVE;
+
+       return filter_signal;
+}
+       
+
+
+
+
 MODULE = SDL::Events   PACKAGE = SDL::Events    PREFIX = events_
 
 =for documentation
@@ -68,3 +105,10 @@ events_wait_event(event = NULL)
                RETVAL = SDL_WaitEvent(event);
        OUTPUT:
                RETVAL
+
+void
+events_set_event_filter(callback)
+       SV* callback
+       CODE:
+       eventfiltersv = callback;
+       SDL_SetEventFilter( (SDL_EventFilter*)eventfilter_cb);
index bede4ed..f4e3b63 100644 (file)
@@ -14,6 +14,8 @@ peep_events
 push_event
 poll_event
 wait_event
+set_event_filter 
+
 /;
 
 my @done_event =qw/
@@ -102,10 +104,13 @@ is( $value, 1, '[wait_event] waited for event');
 my $num_peep_events = SDL::Events::peep_events($event, 127, SDL_PEEKEVENT, SDL_ALLEVENTS);
 is($num_peep_events >= 0, 1,  '[peep_events] Size of event queue is ' . $num_peep_events);
 
+my $callback = sub { print shift->type; return 1; }; 
+SDL::Events::set_event_filter( $callback );
+pass '[set_event_filter] takes a callback';
+
 
 
 my @left = qw/
-seteventfilter 
 eventstate 
 getkeystate 
 getmodstate