这是indexloc提供的服务,不要输入任何密码
Skip to content

Setting Up Visual Studio Code

István Nagy edited this page Mar 29, 2025 · 2 revisions

Lua debugging (Linux or WSL2)

Prerequisites

This guide was written based on an installation with Ubuntu 24.04 inside WSL2, but it should work the same on any ordinary Linux installation.

You should clone and configure the build of CorsixTH as per the Linux compilation instructions tells you. (or you can use the C/C++ extension of VSCode which autodetects the CMakePresets.json, choose linux-dev as preset when asked)

Add debugger hook to CorsixTH source

  • Open CorisxTH/CorisxTH.lua and add the following on top of the file (change the path where your VSCode extension folder resides, in this example I'm using the remote VSCode server's extension path):

      package.path = '/home/user/.vscode-server/extensions/alexeymelnichuk.lua-mobdebug-0.0.5/lua/?.lua' .. ';' .. package.path
      require('mobdebug').start()
    
  • Open CorsixTH/Lua/app.lua and find App:run() function, insert the following to the coroutine function's body as the first line:

      require('mobdebug').on()
    

Create VSCode run configuration and test

  • Switch to the Run & Debug tab in VSCode and create a new "Lua MobDebug: Listen" type debug configuration.
    In the launch.json file replace the autogenerated block with the following (don't forget to edit your executable path where the compiled corsix-th executable resides):

      {
          "name": "Lua MobDebug: CorsixTH",
          "type": "luaMobDebug",
          "request": "attach",
          "workingDirectory": "${workspaceFolder}",
          "sourceBasePath": "${workspaceFolder}",
          "listenPublicly": false,
          "listenPort": 8172,
          "stopOnEntry": false,
          "sourceEncoding": "UTF-8",
          "executable": "${workspaceFolder}/build/dev/CorsixTH/corsix-th"
      }
    
  • Test your setup, place a breakpoint into CorsixTH/Lua/room.lua at Room:initRoom(). Launch the debug configuration Lua MobDebug: CorsixTH from VSCode's menu. Begin a game and try to place a room. Once you try to move to next step from the blueprint, the game should stop and VSCode will jump to the breakpoint and show the stacktrace.

Clone this wiki locally