These pages describe the Lua API. In broad strokes, there are three contexts in which Lua scripts may running
Scripts may run on the physics thread. These are the only scripts allowed to directly interact with the game state. The page on the physics thread gives a good overview of what is possible via this API.
Scripts may run on the rendering thread. These scripts may handle user input and display overlays on top of the game state. See the rendering thread for details.
A special script is placed inside of every level's folder called
setup.lua. This script helps guide the level loading process. See the loading process for details.