中文 | English
Script Development Guide
Wingman scripts are written in Lua or Python and drive automation through the unified wingman module (screen / input / vision / trigger / event, etc.). This page covers the complete flow from your first script to debugging.
Choosing a Language
| Lua | Python | |
|---|---|---|
| Startup speed | Extremely fast | Slower (interpreter cold start) |
| Dependencies | Lua 5.5 only (sol2 bindings) | Python 3 (vcpkg python3 port, currently 3.12.x; embedded via pybind11) |
| Best suited for | High-frequency, low-latency, embedded scenarios | Complex logic, reusing Python third-party libraries |
| Editing/debugging | VS Code + EmmyLua (recommended) | VS Code + Python extension |
For the local GUI, script editing happens exclusively in VS Code; the GUI only loads, runs, and stops scripts. Only the remote Dashboard has a built-in editor.
The Python engine is off by default: officially released runtime packages (release/nightly) bundle only the Lua engine, and running a
.pyscript directly reports that the engine does not exist. To use Python you must build it yourself: add-DWINGMAN_ENABLE_PYTHON=ONto CMake (the vcpkg manifestpythonfeature, which pulls in thepython3+pybind11ports; do not mix in the system CPython). This dimension is covered in the main CI: thecpp-linux-python-testsjob runs the full test suite with Python enabled on Linux, and thecpp-pythonjob validates the Windows link chain.
Your First Script
Lua
hello.lua:
local wingman = require("wingman")
print("Hello Wingman")
local w, h = wingman.screen.getScreenWidth(), wingman.screen.getScreenHeight()
print(string.format("屏幕: %dx%d", w, h))Run it:
wingman-agent script hello.luaPython
hello.py:
from wingman import screen, util
print("Hello Wingman")
w, h = screen.getScreenWidth(), screen.getScreenHeight()
print(f"屏幕: {w}x{h}")Run it (requires a build with the Python engine enabled; see "The Python engine is off by default" above):
wingman-agent script hello.pyOn the Python side the
wingmanmodule surface is identical to Lua's (a unified, engine-agnostic registration), and module functions are exposed under both the original camelCase and snake_case names —screen.getScreenWidth()andscreen.get_screen_width()are equivalent, the latter being PEP 8-compliant.libs/python/typing/provides.pyitype stubs.
Core Modules at a Glance
See the "API" section in the sidebar for the complete API. The most used modules:
| Module | Typical Use | Representative Functions |
|---|---|---|
screen | Pixel/image detection, screenshots | findColor, findImage, capture, getScreenWidth |
input | Mouse/keyboard simulation (with humanization) | click, move, key, type |
vision | Advanced vision (dominant color, template matching, AI detection) | getDominantColor, findImage |
trigger | Conditional triggers | Color appears/disappears, image, hotkey, timer |
event | Publish-subscribe events | on, emit |
task | Task orchestration | Create/wait/cancel |
notify | Notifications (log/toast) | info, warn, error, toast |
http | HTTP client | get, post, put, delete |
human | Humanized input (anti-detection) | Random delays, trajectory-based movement |
util | Utilities (time, sleep, logging) | sleep, getTime, log |
kv / db | Persistence | Key-value store, SQLite |
Note: in Lua everything is accessed through the
wingman.<module>.<fn>namespace afterrequire("wingman"); there are no bare global modules. In Python everything is imported from thewingmanpackage. Treat real usage in examples/lua_scripts/ as the source of truth.
Sandbox Mode
Both local execution paths — the CLI wingman-agent script command and the local GUI (Standalone mode) — force sandboxed execution (apps/agent/src/commands/script_command.cpp and apps/agent/src/standalone_mode.cpp hard-code sandboxed = true). When loading via the wingman.script.load API, the sandboxed config can be specified separately (see the script API). The sandbox surface of both engines:
Lua:
- The globals
io,os,debug, andpackage, along withdofile/loadfile/load, are removed — scripts have no disk-read or system-call path. requireis a controlled shim: onlyrequire("wingman")resolves to the wingman module table; any other module name errors withsandbox: module not allowed: <name>.- Common substitutes: time via
wingman.util.getTime()(epoch milliseconds), files viawingman.file.read/write/exists, waiting viawingman.util.sleep(ms). - No
os.getenv: keys injected through the script configenvare read as_ENV_<KEY>global variables.
Python:
__builtins__is replaced with a whitelist (print/len/range, basic types, exception classes, etc.), and theos/sys/subprocess/io/importlibaliases are cleared.importis taken over by a controlled shim: onlyimport wingman(includingwingman.*submodules andfrom wingman import <module>) is allowed; everything else — including the standard library — raisesImportError: sandbox: module not allowed: <name>. So do notimport time; wait withwingman.util.sleep(ms).- Under the sandbox,
envinjection is disabled (there is noosto read environment variables).
Typical Patterns
Pixel Detection + Click (Color Trigger)
local wingman = require("wingman")
-- findColor(color, region 表, tolerance) 返回单数组:res[1] = 命中点,res[2] = 是否找到
-- (绑定层只回传单个 table,Lua 侧不会展开成多返回值)
local res = wingman.screen.findColor(0xFF0000, {x = 0, y = 0, width = 1920, height = 1080}, 10)
if res[2] then
wingman.input.click(res[1].x, res[1].y)
endLoop Monitoring (with Exit Condition)
local wingman = require("wingman")
for i = 1, 100 do
local res = wingman.screen.findColor(0x00FF00, {x = 0, y = 0, width = 1920, height = 1080}, 10)
if res[2] then
wingman.util.log("检测到目标: " .. res[1].x .. "," .. res[1].y)
break
end
wingman.util.sleep(500) -- 500ms 间隔
endWhen you need all matching points, use
wingman.screen.findColors(color, region, tolerance, maxCount?)instead, which returns an array of points.window.findreturns a single array{handle, found}, just likefindColor.
For more patterns (image matching, hotkey triggers, HTTP integration, macro record/replay), see examples and the Trigger Guide.
Ways to Run
| Mode | Command | Best For |
|---|---|---|
| Single script | wingman-agent script foo.lua | One-off tasks, quick verification |
| Local GUI | wingman-agent start (local capability) + Tauri GUI | Everyday single-machine use with a UI |
| Remote orchestration | wingman-agent start (agent capability) → Go server → Dashboard | Centralized multi-machine control |
For the control paths and architecture constraints of the three modes, see Getting Started - Run Modes and Communication Protocols.
Function Naming Conventions
Module functions are registered in camelCase in their C++ descriptors (e.g. joinTeam, getEventCount). Both script surfaces can use them:
- Lua: only the original camelCase name (
wingman.team.joinTeam(...)). - Python: the original camelCase name and the snake_case alias are exposed simultaneously (
wingman.team.join_team(...)is equivalent towingman.team.joinTeam(...); the aliasing rule matches the engine's internalcamelToSnake). The Python typing stubs (libs/python/typing/wingman/*.pyi) use snake_case as the primary form, with docstrings noting the corresponding camelCase form.
A few functions are registered directly in snake_case (e.g. db.table_insert, human.mouse_move); in that case both languages share the same name. Hand-written pythonic aliases defined in user scripts are not bound by this convention (e.g. timer.after).
Drift guard: python3 scripts/audit_pyi_drift.py compares the C++ module descriptors against the pyi stubs (module surface, function surface, __init__ export surface) and exits non-zero on drift; the api-typing-audit job in CI enforces the same check.
Debugging (Lua / EmmyLua)
- Install the
tangzx.emmyluaextension in VS Code (already recommended by the repository's.vscode/extensions.json). - Completion: the project ships assets/vscode-wingman-lua/ (
wingman.d.luaaggregate plusdefs/per-module import collections), providing type hints for thewingman.*modules. - Breakpoint debugging: the runtime listens on
:9966(EmmyLua attach mode). The VS Codelaunch.jsonis already configured; press F5 to attach. - See the Debugging Guide and the VS Code Development Environment for details.