Skip to content

Plugin structure

my-plugin/
main.lua runs when the plugin loads
lib/util.lua anything else you require
schemas/game.sal the game's types
wraith.json the manifest

Your code runs top to bottom when the plugin loads. Everything comes from require("wraith"), so pull out what you use.

local wraith = require("wraith")
local config, frame, keybinds, ui = wraith.config, wraith.frame, wraith.keybinds, wraith.ui
local settings = config.load({ visible = true })
keybinds.bind("toggle", { name = "Show the window", chord = "ctrl+f8" }, function()
settings.visible = not settings.visible
end)
frame.onFrame(function()
if not settings.visible then return end
ui.window("My Plugin", function()
ui.text("Hello!")
end)
end)

Namespaces use a dot, like wraith.memory.readU32(address). Objects use a colon, like hook:enable().

require("lib.util") loads lib/util.lua from your plugin’s folder, once. Nothing outside the folder can be required.

You mostly don’t. When the plugin unloads, Wraith undoes everything it set up and puts the game’s code back.

config.load(defaults) gives you a table with the saved values on top of your defaults. Change it and it’s saved. Use gameConfig for settings that should be separate for each game.

Put schemas in schemas/ and require("schema") gives you their types.

local types = require("schema")
local player = types.Player.at(address)
player.health = 100

main.lua, callbacks and anything started with wraith.spawn can wait without blocking the game.

wraith.spawn(function()
wraith.frame.next():await()
-- one frame later
end)

It’s Lua 5.5 without the parts that reach outside the game. There’s no io, no dofile or loadfile, and os only has its time functions.

Made with ♥ by Asgard