> ## Documentation Index
> Fetch the complete documentation index at: https://gluals.arnux.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Lua execution

> Run Lua code, files, and commands on your server directly from VS Code while debugging.

## Overview

While connected, run Lua code on the server from VS Code.

All options below except refresh require an execution realm. The selected realm controls where the code runs.

***

## Realm targeting

By default, code runs on the **server** realm. You can change the selected realm in either place:

1. Command Palette → **GLua: Set Realm**
2. Realm selector on bottom status bar

When you target `client`, code runs on all connected players. GLuaLS sends a net message to all clients with the code to execute. You can find this code in the generated `debug.lua` file in `autorun`.

***

## Run selected Lua

1. Select any Lua code in the editor
2. Right-click → **GLua: Run Selected**

GLuaLS sends the selected code to the chosen realm and runs it. Output appears in the **Debug Console**.

***

## Run current file

<Info>
  This runs the saved current file from your workspace. GLuaLS sends the file path to the server for execution.
</Info>

Run the current file:

1. Open the Command Palette (`Ctrl+Shift+P`)
2. Run **GLua: Run Current File**

***

## Run a server command

Execute a SRCDS console command:

1. Open the Command Palette
2. Run **GLua: Run Command**
3. Type the command (e.g., `lua_run print("Hello")`)

The Debug Console shows the output.

***

## Refresh File (Lua Refresh / Hot Reload)

Refresh a file on the server without restarting. Use this if you have Lua refresh disabled.

1. Make your changes in the editor and save
2. Right-click in the editor → **GLua: Refresh File on Server**

This triggers Lua refresh on the specified file.

***

## Debug Console

The **Debug Console** (`Ctrl+Shift+Y`) is the most direct way to interact. Any input is evaluated as a Lua expression on the server (or the targeted realm):

```lua theme={null}
> print(game.GetMap())
gm_flatgrass

> for k, v in pairs(ents.GetAll()) do print(v:GetClass()) end
prop_physics
prop_physics
player
-- ...
```

This works like `lua_run` in the server console, but VS Code shows the output.
