| Author: | Pim Goossens |
|---|---|
| Contact: | irc://irc.freenode.net/6dof |
Contents
Input functionality consists of two parts: first, an input module that polls input devices and generates input events. There is currently just one implementation, which is based on SDL. It should be noted that this SDL-based implementation relies on its video subsystem being used for the game window in order to provide keyboard and mouse input functionality. This is currently the case, but if a new, alternative graphics module is written it will need an accompanying input module as well (unless that graphics module also relies on SDL's graphics subsystem).
The second part is implementation-independent and provides functions that bind input events (generated by the first part) to actions. It is similar to Quake's input system. Events can be tied to special C-based input functions, or to any Lua code.
There's a special prototype for C-based input functions:
typedef void (*input_func)(const struct input_event *event);
This is a convenience to prevent such C-based functions from having to work with the Lua stack in order to get at their arguments. They can be registered as follows:
/* Declare/define move_forward_func as an input_func. */
input_register_func("forward", move_forward_func);
Inputs can then be bound to this function from within Lua:
-- Binds the A key to move_forward_func
input.bind('a', input.funcs.forward)
These commands can be put in the bindings.lua file, which is read during initialization.
The input interface, including struct input_event, is described in input.h, the header file that contains its declaration.