Reload a Lua file from disk
lua_reloadReread an addon or gamemode Lua file from disk and run it in its realms to test edits without reloading the map. Optionally rerun every changed file of a mounted Lua folder.
Instructions
Reads an addon or gamemode file from the disk again and runs it in its realms, to test an edit without reloading the map, in every realm it belongs to in one call. On the machine that hosts the game (singleplayer or listen server) include() from lua_exec also reads the edited file, in the server and the client realm (checked live); a client connected to a separate server (e.g. a local srcds) only has the copies that server sent, so there lua_reload is the way to run an edit on the client. Looks under the mounted Lua folder if any (lua_mount), then lua/, gamemodes/, addons/*/lua|gamemodes/: the engine's order, so the copy the game would load (other matches are listed). Errors name the real file. Running a file again redefines its functions and hooks; what it built at load time (entities, timers, net strings) is not reset. Returns {ok, file, chunkname, realms: {: lua_exec result or {error}}, other_matches?}. Example: {"path": "my_addon/sh_core.lua"} (shared file: runs in server then client). With a mounted folder (lua_mount) there is no autorefresh: mounted_changed: true (instead of path) runs again every file of that folder whose time differs from what each realm loaded (modified, added; the list is status.lua_mount.stale_files), in alphabetical order and in the realms each file belongs to, and returns {ok, mode, path, reloaded: [{file, chunkname, reason, realms: {: lua_exec result or {error}}}], skipped: [{file, why}] (deleted files, entity/weapon/effect files: map_load or lua_reload {path}), realms_without_mount, note?, warning?}; error no_mount if no folder is mounted, error reload_failed (isError, the whole result in details) if a file fails in a realm. Limits: a reload re-runs the file, it does not undo what the old copy did (hooks and timers it added under another name, net strings, entities), and it does not reload a realm that loaded before the folder was mounted (map_load).
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "lua_reload"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| jit | No | Obsolete. gmod-mcp no longer turns the LuaJIT compiler off, neither for this code nor for the functions it defines (hooks and timers run at real speed, timings are real). jit: true now only ignores `budget`. | |
| path | No | The file as include() names it (e.g. 'autorun/my_addon.lua', 'my_addon/sh_core.lua'), a path relative to the game folder ('addons/my_addon/lua/...'), or an absolute path. | |
| depth | No | Cut tables deeper than this (default: no cut). | |
| limit | No | Cut tables longer than this (default: no cut). | |
| budget | No | Optional time limit in seconds, best effort (none by default). It stops loops written in this code itself (error budget_exceeded), not a loop inside a compiled function it calls. Without it, an infinite loop freezes the game: the call fails with main_thread_timeout after timeout_s, status shows main_thread_stalled, and game_terminate ends the game. | |
| fields | No | Keep only these keys of each returned table (e.g. ["pass", "fails"]): the rest of a large result is dropped before it reaches you. Only returned tables are projected: when none is (a JSON string, a number), the result says so in fields_note. | |
| realms | No | Realms to run it in. Default from the name: server/ folder, sv_ prefix or init.lua -> server; client/ folder or cl_ prefix -> client; lua/menu/ -> menu; otherwise server then client (shared file). | |
| instance | No | Optional. Instance identifier (see instances_list). If present and different from the local instance, the call is relayed by the coordinator to that instance. | |
| chunkname | No | Chunk name: the source shown by debug.getinfo, errors and tracebacks, e.g. '@addons/my_addon/lua/my_addon/core.lua' for code that identifies its caller by file. Default: '=mcpagent:lua_exec', or the file's path. | |
| timeout_s | No | How long to wait for the game's answer (default 60, or budget + 10). Past it the call fails with main_thread_timeout; the code may still be running. | |
| max_string | No | Cut strings longer than this (default: no cut). | |
| mounted_changed | No | Instead of `path`: reload every file of the mounted Lua folder (lua_mount) that changed since each realm loaded it (status.lua_mount.stale_files), each in the realms it runs in. Not with `path`. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | Yes | ||
| file | No | ||
| mode | No | ||
| next | No | ||
| note | No | ||
| path | No | ||
| realms | No | ||
| skipped | No | ||
| warning | No | ||
| reloaded | No | ||
| chunkname | No | ||
| next_call | No | ||
| answered_by | No | ||
| other_matches | No | ||
| truncated_note | No | ||
| version_warning | No | ||
| realms_without_mount | No |