2 Copyright (c)2006-2007 - Brett Lajzer
4 See LICENSE for license information.
7 #include "SDL/SDL.h"
#include "lua.hpp"
9 #include "funcs_input.h"
11 //returns the number of joysticks
12 int l_num_joysticks(lua_State
*L
){
13 lua_pushinteger(L
, SDL_NumJoysticks());
18 int l_mouse_state(lua_State
*L
){
19 int x
=0; int y
=0; bool left
=false; bool right
=false;
22 Uint8 mouse_state
= SDL_GetMouseState(&x
, &y
);
23 if(mouse_state
&SDL_BUTTON(1))
25 if(mouse_state
&SDL_BUTTON(3))
28 lua_pushinteger(L
, (lua_Integer
)x
);
29 lua_pushinteger(L
, (lua_Integer
)y
);
30 lua_pushboolean(L
, left
);
31 lua_pushboolean(L
, right
);
36 //return an event to lua
37 int l_get_event(lua_State
*L
){
40 //if there is an event, then return it, else nil
41 if(SDL_PollEvent(&e
)){
44 lua_pushstring(L
, "keyboard");
45 lua_pushstring(L
, "pressed");
46 lua_pushinteger(L
, (int)e
.key
.keysym
.sym
);
50 lua_pushstring(L
, "keyboard");
51 lua_pushstring(L
, "released");
52 lua_pushinteger(L
, (int)e
.key
.keysym
.sym
);
56 lua_pushstring(L
, "mouse");
57 lua_pushstring(L
, "motion");
58 lua_pushinteger(L
,(int)e
.motion
.x
);
59 lua_pushinteger(L
,(int)e
.motion
.y
);
60 lua_pushinteger(L
,(int)e
.motion
.xrel
);
61 lua_pushinteger(L
,(int)e
.motion
.yrel
);
64 case SDL_MOUSEBUTTONDOWN
:
65 lua_pushstring(L
, "mouse");
66 lua_pushstring(L
, "pressed");
67 lua_pushinteger(L
,(int)e
.button
.button
);
68 lua_pushinteger(L
,(int)e
.button
.x
);
69 lua_pushinteger(L
,(int)e
.button
.y
);
72 case SDL_MOUSEBUTTONUP
:
73 lua_pushstring(L
, "mouse");
74 lua_pushstring(L
, "released");
75 lua_pushinteger(L
,(int)e
.button
.button
);
76 lua_pushinteger(L
,(int)e
.button
.x
);
77 lua_pushinteger(L
,(int)e
.button
.y
);
80 case SDL_JOYAXISMOTION
:
81 lua_pushstring(L
, "joystick");
82 lua_pushstring(L
, "axis_motion");
83 lua_pushinteger(L
,(int)(e
.jaxis
.which
+1));
84 lua_pushinteger(L
,(int)(e
.jaxis
.axis
+1));
85 lua_pushinteger(L
,(int)e
.jaxis
.value
);
88 case SDL_JOYBALLMOTION
:
89 lua_pushstring(L
, "joystick");
90 lua_pushstring(L
, "ball_motion");
91 lua_pushinteger(L
,(int)(e
.jball
.which
+1));
92 lua_pushinteger(L
,(int)(e
.jball
.ball
+1));
93 lua_pushinteger(L
,(int)e
.jball
.xrel
);
94 lua_pushinteger(L
,(int)e
.jball
.yrel
);
97 case SDL_JOYHATMOTION
:
98 lua_pushstring(L
, "joystick");
99 lua_pushstring(L
, "hat_motion");
100 lua_pushinteger(L
,(int)(e
.jhat
.which
+1));
101 lua_pushinteger(L
,(int)(e
.jhat
.hat
+1));
102 lua_pushinteger(L
,(int)e
.jhat
.value
);
105 case SDL_JOYBUTTONDOWN
:
106 lua_pushstring(L
, "joystick");
107 lua_pushstring(L
, "pressed");
108 lua_pushinteger(L
,(int)(e
.jbutton
.which
+1));
109 lua_pushinteger(L
,(int)(e
.jbutton
.button
+1));
112 case SDL_JOYBUTTONUP
:
113 lua_pushstring(L
, "joystick");
114 lua_pushstring(L
, "released");
115 lua_pushinteger(L
,(int)(e
.jbutton
.which
+1));
116 lua_pushinteger(L
,(int)(e
.jbutton
.button
+1));
120 lua_pushstring(L
, "quit");
124 case SDL_VIDEORESIZE
:
125 break; //not supported yet
126 case SDL_VIDEOEXPOSE
:
127 break; //not supported yet