Skip to content
Anthony Samms edited this page Jun 2, 2026 · 2 revisions

The ScriptManager is the global Lua runtime for the game. It owns the sol::state, discovers and indexes all Lua scripts in the active skin, and registers the C++ bindings that scripts can call. A single instance, script_manager, is available globally.

ScriptManager

Members

Member Type Description
lua unique_ptr<sol::state> The Sol2/Lua state; created in init() and destroyed in shutdown()
tex TextureWrapper A texture wrapper initialised to the skin's Graphics/ directory, accessible from Lua via the tex table
scripts map<string, string> Maps script name to absolute file path; populated during init()

Methods

void init(fs::path script_path);

Creates the Lua state and opens the base, package, string, math, and table standard libraries. Sets package.path so scripts can require siblings or sub-modules inside script_path. Walks script_path and indexes every .lua file and every directory that contains a matching <dir>/<dir>.lua entry into scripts. Initialises tex against script_path/../Graphics/, then calls register_lua_bindings().

void shutdown();

Unloads all textures held by tex and resets the lua state.

string get_lua_script_path(const string& script_name);

Returns the absolute path for a named script. Throws std::runtime_error if script_name is not in the index.

void register_lua_bindings();

Registers all C++ types and global tables that scripts can use. See the sections below.


Lua bindings

Animation types

All animation classes are exposed as Lua usertypes inheriting from BaseAnimation.

Lua type C++ class
BaseAnimation BaseAnimation
FadeAnimation FadeAnimation
MoveAnimation MoveAnimation
TextureChangeAnimation TextureChangeAnimation
TextStretchAnimation TextStretchAnimation
TextureResizeAnimation TextureResizeAnimation

All expose update(t) (returns the current attribute), restart(), start(), pause(), unpause(), reset(), plus read-access to attribute, duration, is_finished, is_started, isFinished, isStarted.

anim table

Helper functions for constructing animation objects from Lua.

anim.fade(duration, params?)

Creates a FadeAnimation. params is an optional table with fields: initial_opacity, final_opacity, delay, loop, lock_input, ease_in, ease_out, reverse_delay.

anim.move(duration, params?)

Creates a MoveAnimation. params: total_distance, start_position, delay, loop, lock_input, ease_in, ease_out, reverse_delay.

anim.texture_change(duration, textures, params?)

Creates a TextureChangeAnimation. textures is an array of {start, end, index} triples. params: delay, loop, lock_input.

anim.text_stretch(duration, params?)

Creates a TextStretchAnimation. params: delay, loop, lock_input.

anim.texture_resize(duration, params?)

Creates a TextureResizeAnimation. params: initial_size, final_size, delay, loop, lock_input, ease_in, ease_out, reverse_delay.

tex table

Functions for working with textures from Lua.

Function Description
tex.load_animations(screen_name) Loads animation definitions for a skin screen
tex.get_animation(anim_id, is_copy?) Returns a BaseAnimation* from the skin animation table; is_copy = true returns an independent copy
tex.load_folder(screen_name, subset) Loads a texture subset folder
tex.unload_folder(screen_name, subset) Unloads a texture subset folder
tex.get_screen_width() Returns the screen width in pixels
tex.get_screen_height() Returns the screen height in pixels
tex.get_screen_scale() Returns the current DPI/resolution scale factor
tex.get_skin_config(config_key) Returns a table {x, y, font_size, width, height} for a skin layout config entry, or nil
tex.get_texture_keys(subset) Returns an array of texture name strings available in subset, or nil
tex.get_texture_info(subset, texture_name) Returns {name, x, y, width, height, frame_count} for a texture, or nil
tex.draw_texture(subset, texture_name, params?) Draws a named texture with optional draw parameters
tex.get_id(subset, texture_name) Returns the numeric TexID for a named texture, or nil
tex.draw_id(id, params?) Draws a texture by its numeric TexID

Draw parameters

All draw_texture and draw_id calls accept an optional params table with these fields:

Field Type Description
color {r, g, b, a} Tint colour (0–255 per channel)
frame int Frame index for animated/framed textures
scale float Uniform scale multiplier
center bool Draw centred on (x, y) instead of top-left
x float Horizontal offset from the texture's configured position
y float Vertical offset
x2 float Second x value (used as width for stretched draws)
y2 float Second y value (used as height for stretched draws)
rotation float Rotation in degrees
fade float Opacity (0–1)
index int Secondary index (e.g. texture variant)
mirror string "horizontal" or "vertical"
origin {x, y} Rotation/scale origin point
src {x, y, w, h} Source rectangle for sub-texture draws

text table

text.create_text(skin_config_key, color, outline_color, is_vertical, outline_thickness, spacing)

Creates an OutlinedText object using the font size and text string from the named skin config entry. color and outline_color are {r, g, b, a} arrays. Returns an OutlinedText usertype.

OutlinedText usertype

Field/Method Description
width Text width in pixels
height Text height in pixels
is_ready Whether the texture has been uploaded to the GPU
upload_pending Whether a GPU upload is queued
finish() Forces synchronous GPU upload
draw(params?) Draws the text with optional draw parameters (same fields as texture draw params)

Clone this wiki locally