Search Results for

    Show / Hide Table of Contents

    Debug Lua with breakpoints

    中文 | English

    Run this command at the repository root to replay the examples through the local Unity MCP.

    python Docs/Manual/manual/tools/tutorials.py run lua-breakpoint-debugging
    

    Install VS Code and EmmyLua, then open the Lua source that matches the running target.

    1. In Run and Debug, select EmmyLua Attach Debug and choose your local Unity Editor or game process, such as PanzerWar-DE. Attach debugging requires Lua symbols in the target.
    2. Set a breakpoint to the left of the line number. Trigger the script in game, for example by starting the Hello World behaviour.
    3. When the breakpoint is hit, open Variables and use Step Over. If it remains unbound, check that both the file path and source match the running script.

    The replay checks line information and local variables in the project's xLua. Test VS Code attachment and symbol availability with the specific build.

    Click to expand MCP actionsClick to collapse MCP actions
    [
      {
        "tool": "invoke",
        "arguments": {
          "path": "static:ShanghaiWindy.Core.AssetBundleManager/LuaEnv/DoString",
          "args": [
            "local source = \"@manual-breakpoint-example.lua\"\nlocal handler = assert(load(\"local total = 8\\nlocal sum = total + 4\\nreturn sum\", source))\nlocal observed\nlocal thread = coroutine.create(function()\n    debug.sethook(function(_, line)\n        if line == 2 and debug.getinfo(2, \"S\").source == source then\n            local name, value = debug.getlocal(2, 1)\n            if name == \"total\" then observed = value end\n        end\n    end, \"l\")\n    local result = handler()\n    debug.sethook()\n    assert(result == 12 and observed == 8)\nend)\nlocal ok, err = coroutine.resume(thread)\nassert(ok, err)\nreturn \"Lua line information verified\"\n",
            "manual-breakpoint",
            "null"
          ]
        },
        "expect": {
          "contains": "Lua line information verified"
        }
      }
    ]
    
    In this article
    Back to top Panzer War Document