From: Kartik Thakore Date: Thu, 12 Nov 2009 02:37:51 +0000 (-0500) Subject: Wrote a really shotty callback need someone to review it. Need to devise testplan... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=633f388bbc161bfc5177fb49e482c8cfb27b60aa;p=sdlgit%2FSDL_perl.git Wrote a really shotty callback need someone to review it. Need to devise testplan for it. But 30t/core_events.t SDL::Events --- diff --git a/src/Core/Events.xs b/src/Core/Events.xs index 090ae6c..3451610 100644 --- a/src/Core/Events.xs +++ b/src/Core/Events.xs @@ -9,6 +9,43 @@ #include #include +/* 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); diff --git a/t/core_events.t b/t/core_events.t index bede4ed..f4e3b63 100644 --- a/t/core_events.t +++ b/t/core_events.t @@ -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