From cd9552ee58014bd1f0ce88e197ea59db53631fc3 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Wed, 19 Jan 2011 21:37:46 +0000 Subject: [PATCH] Lua: Added waitinput(), for more interactive scripts. Works well, but kept under observation for better ideas etc. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1689 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/factory.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/factory.c b/src/factory.c index 2f30e7f6..b310f577 100644 --- a/src/factory.c +++ b/src/factory.c @@ -1007,6 +1007,52 @@ int L_WaitBreak(lua_State* L) return 1; } +int L_WaitInput(lua_State* L) +{ + float delay; + Uint32 end; + int nb_args=lua_gettop(L); + int moved; + + /*word key; + word button; + word mouse_x; + word mouse_y;*/ + + LUA_ARG_LIMIT (1, "waitinput"); + LUA_ARG_NUMBER(1, "waitinput", delay, 0.0, DBL_MAX); + + // Simple 'yield' + if (delay == 0.0) + { + moved=Get_input(0); + } + else + { + // Wait specified time + end = SDL_GetTicks()+(int)(delay*1000.0); + + moved=0; + do + { + moved=Get_input(20); + } while (!moved && SDL_GetTicks()