accessing C union members...

new topic     » topic index » view thread      » older message » newer message

Hello, I am trying to access a C union in a dll. The Union looks like this:

typedef union{ 
  Uint8 type; 
  SDL_ActiveEvent active; 
  SDL_KeyboardEvent key; 
  SDL_MouseMotionEvent motion; 
  SDL_MouseButtonEvent button; 
  SDL_JoyAxisEvent jaxis; 
  SDL_JoyBallEvent jball; 
  SDL_JoyHatEvent jhat; 
  SDL_JoyButtonEvent jbutton; 
  SDL_ResizeEvent resize; 
  SDL_ExposeEvent expose; 
  SDL_QuitEvent quit; 
  SDL_UserEvent user; 
  SDL_SywWMEvent syswm; 
} SDL_Event; 

First, I want to check that type equals a certain value then I need to access the SDL_MouseButtonEvent member. It looks like so:

typedef struct{ 
  Uint8 type; 
  Uint8 which; 
  Uint8 button; 
  Uint8 state; 
  Uint16 x, y; 
} SDL_MouseButtonEvent; 

Here is my code:

global function viewScrollWheel() 
 
	atom sdl_event 
	integer mwheel, etype, button 
	 
	etype = 0 
	button = 0 
		 
	sdl_event = allocate(100)	-- allocate enough memory for event structure 
	 
	while(SDL_PollEvent(sdl_event)) do   -- loop thru events 
	 
		etype = peek(sdl_event)   --get type member from event? 
		 
		if etype = SDL_MOUSEBUTTONDOWN then  -- if type = MBD then  
			button = 1		    -- making sure we are here...	 
		        exit					 
		end if 
	 
	end while 
	 
	free(sdl_event) 
 
	return button 
	 
end function 

I want to check the type field in the event union and if it equals SDL_MOUSEBUTTONDOWN then I want to check the button field that is part of the struct. Any help is appreciated!

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu