rude avatar rude committed 5ccd923

Added love.event.clear, because why not. (Issue #202).

Comments (0)

Files changed (4)

src/modules/event/sdl/Event.cpp

 		return ok && (SDL_PushEvent(&e) == 0);
 	}
 
+	void Event::clear()
+	{
+		static SDL_Event e;
+
+		while(SDL_PollEvent(&e))
+		{
+			// Do nothing with 'e' ...
+		}
+	}
+
 	bool Event::convert(SDL_Event & e, Message & m)
 	{
 		switch(e.type)

src/modules/event/sdl/Event.h

 		**/
 		bool push(Message & message);
 
+		/**
+		 * Clears the event queue.
+		 */
+		void clear();
+
 	private:
 
 		bool convert(SDL_Event & e, Message & m);

src/modules/event/sdl/wrap_Event.cpp

 		return 1;
 	}
 
+	int w_clear(lua_State * L)
+	{
+		instance->clear();
+		return 0;
+	}
+
 	// List of functions to wrap.
 	static const luaL_Reg functions[] = {
 		{ "pump", w_pump },
 		{ "poll", w_poll },
 		{ "wait", w_wait },
 		{ "push", w_push },
+		{ "clear", w_clear },
 		{ 0, 0 }
 	};
 

src/modules/event/sdl/wrap_Event.h

 	int w_poll(lua_State * L);
 	int w_wait(lua_State * L);
 	int w_push(lua_State * L);
+	int w_clear(lua_State * L);
 
 	extern "C" LOVE_EXPORT int luaopen_love_event(lua_State * L);
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.