首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用Love2D调试Lua Love2D?

如何用Love2D调试Lua Love2D?
EN

Stack Overflow用户
提问于 2020-11-29 22:45:37
回答 1查看 2K关注 0票数 3

我正在寻找关于如何在Visual Studio代码中调试Lua代码的建议。我使用的是Love2D,所以我知道我需要在某种程度上嵌入我的调试代码,因为它不是独立的Lua,但是我更喜欢对我的源代码进行最少的扩展。

目标:在VSCode中定期使用断点、捕获错误和变量检查进行调试。我不介意我使用哪个扩展,只要我能够轻松地调试我的代码。

到目前为止我尝试过的是:

  1. Lua调试器:不知怎么的,它碰到了一个断点,但只有在调用debuggee.poll()时,我才无法进一步介入或检查。
  2. LRDB:看起来很有希望,但不知怎么的,游戏还是不会开始的。它就挂着直到我把它交给任务经理。

LRDB的代码(不包括泛型更新/绘制函数,因为它们只是用于测试断点):

代码语言:javascript
复制
local lrdb = require "lrdb_server"
local db_port = 21110

function love.run()
    lrdb.activate(db_port)

    if love.load then love.load(love.arg.parseGameArguments(arg), arg) end
 
    -- We don't want the first frame's dt to include time taken by love.load.
    if love.timer then love.timer.step() end
 
    local dt = 0
    lrdb.deactivate()
    -- Main loop time.
    return function()
        lrdb.activate(db_port)
        -- Process events.
        if love.event then
            love.event.pump()
            for name, a,b,c,d,e,f in love.event.poll() do
                if name == "quit" then
                    if not love.quit or not love.quit() then
                        return a or 0
                    end
                end
                love.handlers[name](a,b,c,d,e,f)
            end
        end
 
        -- Update dt, as we'll be passing it to update
        if love.timer then dt = love.timer.step() end
 
        -- Call update and draw
        if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
 
        if love.graphics and love.graphics.isActive() then
            love.graphics.origin()
            love.graphics.clear(love.graphics.getBackgroundColor())
 
            if love.draw then love.draw() end
 
            love.graphics.present()
        end
 
        if love.timer then love.timer.sleep(0.001) end
        lrdb.deactivate()
    end
end

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-29 23:00:52

几秒钟后,我发现了一个可行的解决方案这里

安装:本地Lua调试器

将此添加到launch.json

代码语言:javascript
复制
    [
        {
            "type": "lua-local",
            "request": "launch",
            "name": "Debug Love",
            "program": {
                "command": "/usr/bin/love"
            },
            "args": [ "${workspaceFolder} "]
        }
    ]

放:

代码语言:javascript
复制
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
    require("lldebugger").start()
end

在您的main.lua文件之上。

享受调试吧!

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65066037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档