Nanfeng

Notes on software development, code, and curious ideas

Debugging a quick-Cocos2d-x Lua Project in VS Code

This is the configuration that allowed an older quick-Cocos2d-x project to run and debug from VS Code on Windows.

1. Install the Lua debugger

The original setup used the luaide-lite extension. Other Lua debuggers use different launch fields, so follow the selected extension’s own documentation.

luaide-lite VS Code extension

2. Add launch.json

Open Run and Debug and create .vscode/launch.json. Keep the extension’s Cocos-launch configuration and set exePath to the project’s player3 executable, which was the path that worked in this environment.

Cocos launch executable path

At this stage the player can launch, but Lua breakpoints still require the debug bootstrap.

3. Add LuaDebug.lua

Place the debugger’s LuaDebug.lua file in the project’s src directory.

LuaDebug.lua in the source folder

Historical debug helper used by the project

Review third-party debug code before running it and keep its listening socket limited to local development.

4. Initialize it from main.lua

Add:

1
2
3
4
5
6
local breakSocketHandle, debugXpCall = require("LuaDebug")("127.0.0.1", 7003)
cc.Director:getInstance():getScheduler():scheduleScriptFunc(
breakSocketHandle,
0.3,
false
)

Make sure the port matches the VS Code configuration and remove or disable the remote-debug bootstrap from production builds.

+