views:

377

answers:

1

In a related question I asked how to get input via IUP. This works fine, except that it goes through the system, and is subject to the repreat rate which is not optimal for a game. What I would really like is the ability to obtain the current state of any key at a given time. Is there a way to do this (through IUP or otherwise)?

+1  A: 

You will probably need to wrap calls to either the appropriate Win32 API, DirectX, or whatever in a lua module. Catching key stroke events in IUP requires that the be delivered to the window or control via the "normal" Windows Message mechanism, and is likely not the best approach in a game framework.

You can use an IUP timer object to run a redraw on a schedule, but you still need a way to collect the keyboard state. If you want to use a gamepad, joystick, or any HID other than the keyboard and mouse, then IUP won't directly help in any case.

This is easily done with a small amount of C code compiled to a DLL.

It can be done fairly easily with SWIG, for some kinds of API. Others will take enough setup/teardown work that it is easier to just handcraft the wrapping.

There is also the Alien module for Lua that allows direct calls into arbitrary APIs from pure Lua. Alien is included as part of Lua for Windows, as well as through its project page at Luaforge. Alien itself is even somewhat portable across platforms, although nothing you'd call with it is.

Something else to look at as you pursue this path is one or more of the existing game engines. Usually, these hide the event loop inside the engine (as does IUP) but they are optimized for game building rather than desktop applications.

There are a number out there that I've heard rumors of on the Lua mailing list. One that comes to mind because its been mentioned fairly often is LÖVE.

RBerteig
I'm currently looking into LÖVE, and so far I am quite impressed. This seems like what I was looking for in the first place.
Cristián Romo