Lua开发环境ZeroBraneStudio调试

比起我搞不定的VScode的Lua调试插件,ZeroBraneStudio的调试功能完善且容易上手。然鹅这款IDE的默认配色实在很丑(在配色方案偏好设置最后一行告诉了怎么玩预设的几款配色,DIY一下还是看得过去的)。

如何让ZBStudio开发体验像VScode一样Smooth呢?官方指南

本文介绍了几个Customization Tricks:

原生快捷键速查
复制操作
  • Ctrl-D: Duplicate selection or current line 复制当前行
删除操作
  • Shift+Tab: Unindent line or current selection 删除一格Tab缩进
  • Shift+Delete: Delete line 删除当前行
跳转操作
  • Ctrl-[ : Jump to previous paragraph
  • Ctrl-] : Jump to next paragraph
  • Ctrl-Left/Right: Jump to start/end of line
  • Ctrl-Tab:切换文件
  • Ctrl-Alt-Click: Jump to definition (if there is a variable under cursor)
  • Alt-Left: Jump to previous position after Jump to definition
选中操作
  • Shift-cursor: selection
  • Alt-Shift-cursor: Block selection
  • Ctrl-Shift-[: Extends selection to previous paragraph
  • Ctrl-Shift-]: Extends selection to next paragraph
  • Ctrl-Shift-Left/Right: Extends selection to previous word
整体操作
  • Ctrl+U: Comment/uncomment
  • Ctrl+I: Correct Indention
  • Ctrl-MouseWheel: Magnify/Reduce text size
  • Alt+A+Cursor (Ctrl-DblClick): Rename all instances of current variable

Ctrl+Shift+O: 打开/关闭console

修改快捷键

官方指南 bind-new-keyboard-shortcuts-docs

To support more actions: keyboard-commands-list

举个栗子, 以下修改的文件其实是/opt/zbstudio/src/editor/keymap.lua

如果你不想改动源码文件的话,同样的修改对于/opt/zbstudio/cfg/user.lua一样生效。

  1. 增加操作

    ide.config.editor.keymap = {
        --...
        --删除当前行
        ["Shift-Delete"] = {("DEL"):byte(), wxstc.wxSTC_SCMOD_SHIFT, wxstc.wxSTC_CMD_DELLINERIGHT, "Unix"},
        --...
    }
    
  2. 对已有的操作重定义快捷键

    ide.config.keymap = {
        --...
        --修改前是空值,这个操作是选中所有instance重命名,默认是由Ctrl-DblClick触发,修改后还可以由Alt+A触发。
    [ID.RENAMEALLINSTANCES] = "Alt-A",
        --修改前是空值,这个操作是将选中的变量快速添加到watch项,修改后可以用F1触发。
    [ID.QUICKADDWATCH] = "F1",
        }
    
Lua调试
条件断点conditional breakpoint

在zerobrane studio中,我们想要调试一个脚本如下:

local foo = 0
for i = 1, foo+5 do
    foo = i
    print("Loop")
end

我们在第3行打上断点,但是我们只想调试当i=3的时候,这样写,

local dbg=require("mobdebug")
dbg.start()
dbg.off()

local foo = 0
for i = 1, foo+5 do
    --进入调试状态
    if(i==3)then
        dbg.on()
    end

    foo = i
    print("Loop")

    --退出调试状态
    if(i==3)then
        dbg.off()
    end
end

执行(F6)脚本即可,我们设置的断点就是一个条件断点了。

协程调试coroutine debugging

The debugging of coroutines is disabled by default. To enable debugging in coroutines, including stepping into resume/yield calls and triggering of breakpoints, you may do one of the following:

  • add require('mobdebug').coro() call to your script
  • add require('mobdebug').on() call to that coroutine fragment
Watch窗口和Stack窗口

You can drill down to get values of individual elements in tables in these windows.

  • inspect variables and expressions View | Watch Window
    • after every stopping in the debugger
    • change the values
  • view the call stack View | Stack Window
    • the call stack frames with function names
    • for each of the stack frames, presents all local variables and upvalues
快捷键功能
InsertAdd watch
DeleteDelete Watch
F1Quick Add Watch
语法检查

The Static analyzer allows to detect typos, non-localized variables, and unused parameters. Before running your code:

  • execute the analysis on the current file Project | Analyze
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值