When main() is called, the first thing the game does is create the
Lua environment and initialize it, then execute the init.lua
script, which in turn runs config.lua to set up the configuration
table, then loads the Lua utility functions in util.lua and
vector.lua, and finally processes the commandline.
Controls goes back to C at which point the lua_funcs will be
registered (this step may later be performed before running
init.lua). The game then proceeds by initializing each subsystem
(audio, graphics, input) and the game world code, and finally
running bindings.lua to load the user's input configuration.
What happens at this point is subject to some major change as the game
develops. Currently, a level is loaded as indicated by some
configuration values and the main game loop is entered immediately.
The game has a global table to store configuration values. Its purpose
is to make certain parameters easily adjustable by the user, and
easily accessible by the game's code (even its C code). Here's how it
works and how to use it:
In the early stage of game initialization, a special Lua table
called config is created and loaded with values from
defaults.lua. This file contains initial (default) values for
the options. At the same time, it determines what options exist; it
is not possible to add new options after initialization.
Immediately after this, the game parses the commandline used to run
it. Commandline options can be used to override the default values
specified in defaults.lua. The game looks for arguments of the
form --option=value, --no-option, and --option. The
first form assigns a string or number value to an option. The second
and third forms disable and enable a boolean (on/off) option,
respectively.
From within the Lua environment, options can be accessed as
config.optionname. For example:
print(('The current screen mode is %dx%dx%d'):format(
config.width, config.height, config.bpp
))
In C code, use the config_get_int, config_get_float, and config_get_str functions. config_get_int is also used for booleans. Example:
printf("Current mouse sensitivity: x=%f, y=%f\n",
config_get_float("mousesensx"), config_get_float("mousesensy")
);
printf("Joystick is %s\n",
config_get_int("joystick") ? "enabled" : "disabled"
);
Options can be changed from within the Lua environment, but there
are no equivalent config_set_* functions in C. Currently, most
(if not all) options are used only during initialization, so
changing them afterwards has no effect. This may change if/when
configuration events are introduced (see below).
That's pretty much all there is to it. To introduce a new option all
you have to do is add it to defaults.lua, and you can start using
it.
Later on, an event system may be introduced that can notify modules of
changes in the configuration, so they can use local variables to hold
parameters and don't have to repeatedly poll the config table.