From 2c8c4bc567b09996ee69584a7229356cd411c51a Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Tue, 31 May 2011 18:38:13 +0100 Subject: [PATCH] Pass mouse coordinates (mousex, mousey, mouseb, mousebq) and Lua click handling --- build/test.lua | 2 ++ includes/luaconsole.h | 2 +- src/luaconsole.c | 16 +++++++++++----- src/main.c | 14 ++++++++------ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/build/test.lua b/build/test.lua index f57f02b8d..fbb062fbd 100644 --- a/build/test.lua +++ b/build/test.lua @@ -9,4 +9,6 @@ function do_step() increment = 2 end tpt.drawtext(numberthing, 50, "Oh my god, this is amazing", 255, 255, 255, 255) + tpt.drawtext(mousex, mousey, "Oh my god, this is amazing", 255, 255, 255, 255) + return true end diff --git a/includes/luaconsole.h b/includes/luaconsole.h index cb1bb12d0..187bf01b5 100644 --- a/includes/luaconsole.h +++ b/includes/luaconsole.h @@ -6,7 +6,7 @@ #include void luacon_open(); -int luacon_step(); +int luacon_step(int mx, int my, int mb, int mbq, char key); int luacon_keypress(char key); int luacon_eval(char *command); char *luacon_geterror(); diff --git a/src/luaconsole.c b/src/luaconsole.c index 53f81f07c..9e55d760e 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -34,17 +34,23 @@ void luacon_open(){ luaL_openlibs(l); luaL_openlib(l, "tpt", tptluaapi, 0); } -int luacon_step(){ +int luacon_step(int mx, int my, int mb, int mbq, char key){ if(step_function && step_function[0]){ + //Set mouse globals + lua_pushinteger(l, mbq); + lua_pushinteger(l, mb); + lua_pushinteger(l, my); + lua_pushinteger(l, mx); + lua_setfield(l, LUA_GLOBALSINDEX, "mousex"); + lua_setfield(l, LUA_GLOBALSINDEX, "mousey"); + lua_setfield(l, LUA_GLOBALSINDEX, "mouseb"); + lua_setfield(l, LUA_GLOBALSINDEX, "mousebq"); lua_getfield(l, LUA_GLOBALSINDEX, step_function); lua_call(l, 0, 0); + return lua_toboolean(l, -1); } return 0; } -int luacon_keypress(char key){ - //Nothing here yet - return 0; -} int luacon_eval(char *command){ return luaL_dostring (l, command); } diff --git a/src/main.c b/src/main.c index c7e325d91..bbaee6887 100644 --- a/src/main.c +++ b/src/main.c @@ -2372,9 +2372,9 @@ int main(int argc, char *argv[]) } } } -#ifdef LUACONSOLE - luacon_keypress(sdl_key); -#endif +//#ifdef LUACONSOLE + //luacon_keypress(sdl_key); +//#endif #ifdef PYCONSOLE if (pyready==1 && pygood==1) if (pkey!=NULL && sdl_key!=NULL) @@ -2466,6 +2466,11 @@ int main(int argc, char *argv[]) bq = b; // bq is previous mouse state b = SDL_GetMouseState(&x, &y); // b is current mouse state +#ifdef LUACONSOLE + if(luacon_step(x, y, b, bq, sdl_key)) + b = 0; //Mouse click was handled by Lua step +#endif + for (i=0; i