Skip to content

Lua Debugging (VSCode)

Ben Dol edited this page Dec 8, 2023 · 7 revisions

Lua Debugging

Will be added in https://github.com/mehah/otclient/pull/671/files (remove me when merged)

Step 1 - Open & Build

Open & build your the project in VSCode (make sure you build using debug, i.e. Windows - Debug (MSVC))

Step 2 - Install Extension

Install the VSCode Local Lua Debugger extension

Step 3 - Configure Extension

Go to File > Preferences > Settings and search for Lua-local: Interpreter make sure this is set to lua5.1

Step 4 - Add launch.json Configuration

Add the following configuration to your otclient/.vscode/launch.json configuration file (if it doesn't exist create it and paste all of the below into it. Otherwise add just the contents of "configurations": [ as a new configuration).

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lua-local",
            "request": "launch",
            "name": "Debug Lua Executable",
            "program": {
                "command": "${workspaceFolder}/otclient.exe"
            },
            "args": [
                "${workspaceFolder}"
            ],
            "scriptRoots": [
                "${workspaceFolder}/modules",
                "${workspaceFolder}/mods"
            ],
            "scriptFiles": [
                "${workspaceFolder}/modules/**/*.lua",
                "${workspaceFolder}/mods/**/*.lua"
            ],
        }
    ]
}

Step 5 - Launch in debug

Launch the new launch configuration Debug Lua Executable

image

Step 6 - Start debugging!

Now you can add breakpoints to your lua code directly and profit. lua-debug