# File lib/ruby-sdl-ffi/sdl/event.rb, line 275
  def self.PeepEvents( events, action, mask )
    # PeepEvents is very versatile, so we break it up into
    # different actions...

    case action

    # Append the given events to the queue, return number added.
    when ADDEVENT
      numevents = events.size
      mp = FFI::Buffer.new( SDL::Event, numevents )

      # Dump the events into the Buffer as raw, hardcore bytes
      events.each_with_index do |ev, i|
        mp[i].put_bytes( 0, ev.pointer.get_bytes(0, ev.size) )
      end

      return __SDL_PeepEvents( mp, numevents, action, mask )
      
    # Peek or Get the first N events and return them in an array.
    # Peek does not remove them from the queue, but Get does.
    when PEEKEVENT, GETEVENT
      numevents = events.to_i
      mp = FFI::Buffer.new( SDL::Event, numevents )
      n = __SDL_PeepEvents( mp, numevents, action, mask )

      # Something went wrong
      return nil if( n == -1 )

      events = []
      n.times do |i|
        events << Event.new( mp[i] ).unwrap
      end

      return events
    end
  end