如何使用 VSCode 调试 Lua Love2D?
2020-11-29 22:45:38
收藏:0
阅读:288
评论:1
我正在寻找有关如何在 Visual Studio Code 中调试 Lua 代码的建议。我正在使用 Love2D,所以我理解我需要嵌入我的调试代码,因为它不是独立的 Lua,但我更喜欢对我的源文件进行最小的增量。
目标:在 VSCode 中进行常规调试,包含断点、捕获错误和变量检查。 我无论使用哪个扩展名,只要能够轻松调试我的代码即可。
我迄今为止尝试过的方法:
Lua Debugger:它以某种方式起作用,它碰到一个断点,但只有在调用
debuggee.poll()时才会触发,从那里我无法进一步调试或检查。LRDB:看起来很有前途,但一些游戏无法启动。 它只是挂起,直到我用任务管理器杀死它。
LRDB 的代码(未包括通用的 update/draw 函数,因为它们只是用于测试断点):
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
希望能得到帮助。
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

我刚刚在这里偶然发现了一个可行的解决方案 here。
安装: 本地 Lua 调试器
将以下内容添加到您的
launch.json文件中:[ { "type": "lua-local", "request": "launch", "name": "Debug Love", "program": { "command": "/usr/bin/love" }, "args": [ "${workspaceFolder} "] } ]将以下内容放在您的
main.lua文件的顶部:if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then require("lldebugger").start() end如果您没有重载
love.run,可以使用此代码片段捕获所有错误,因为我发现有些错误可能无法正确捕获:if os.getenv "LOCAL_LUA_DEBUGGER_VSCODE" == "1" then local lldebugger = require "lldebugger" lldebugger.start() local run = love.run function love.run(...) local f = lldebugger.call(run, false, ...) return function(...) return lldebugger.call(f, false, ...) end end end享受调试吧!