Solarus quests  1.5
Quest maker's reference
Solarus 1.5 - Lua API reference

This is the API specification of Lua functions, methods, callbacks and types defined by Solarus. This documentation page is intented to quest makers who want to write scripts for their maps, items, enemies and menus. For the point of view of the C++ code of the engine, see the documentation of class LuaContext.

Most of the data types defined in the C++ engine (like sprites, map entities, movements, savagames, etc.) are exported as Lua types in the scripting API of Solarus. We give here the full reference of these types and the functions available for each type. The API exports C++ functions and C++ datatypes that may be used by your scripts. Examples of such features are creating a sprite, drawing an image or moving an enemy. In the opposite way, Solarus will also call your own Lua functions (if you define them), for example to notify your script that an enemy has reached an obstacle, that a pressure plate has just been activated or that the hero is talking to a particular non-playing character.

The following script files are loaded by the engine when they exist:

  • The main script (main.lua): global script that controls the menus (if any) before starting a game and decides to start a game.
  • The script of a map (maps/XXXX.lua): controls the map XXXX. Called when the player enters the map.
  • The script of an enemy (enemies/XXXX.lua): controls an enemy whose breed is XXXX. Called when an enemy of this breed is created on the map.
  • The script of an item (items/XXXX.lua): controls the equipment item named XXXX. Called when a savegame is loaded or created.

All these various scripts run in the same Lua state. In other words, they share global values.

Interactions between your Lua world and the engine are managed through a predefined global table called sol. The whole Solarus Lua API is available in the sol table. It contains functions, types and values that allow you to interact with the C++ engine.

Most types of the Lua API (game, item, map, entity, movement and sprite) are Lua userdata that have something special: they can also be indexed like tables. This mechanism is used by the engine when it needs to invoke callback methods that you defined on your objects. But you can also extend these objects with your own functions and data. This is very useful in the game and map objects to implement and store everything that is not built-in in the Solarus API: your pause menu, your HUD, a puzzle, or some properties and utility functions specific to your quest.

The following features are defined in the global sol table. See the specification page of each feature for more details.

  • sol.main: some general-purpose features.
  • playing musics and sounds.
  • setting the video mode.
  • sol.input: checking keyboard and joypad state.
  • sol.file: directly accessing data files.
  • showing various information on the screen.
  • sol.language: handling translations.
  • sol.timer: making an action later with a delay.
  • sol.sprite, sol.surface, sol.text_surface: displaying animated images, fixed images or text, respectively.
  • sol.movement: moving objects.
  • handling data saved (life, equipment, etc.) and running a game.
  • sol.item: controls a particular type of equipment item and its behavior.
  • handling the current map and its properties (only during a game).
  • sol.entity: controls entities placed on the map (only during a game), like the hero, enemies, chests, non-playing characters, etc.