Latest post of the previous page:
Набор макросов, позволяющих управлять отладкой прямо из фара.
Клавиатурные сочетания аналогичны имеющимся в IDE (кроме CtrlF5 и AltF5).
Большая часть макросов предназначена для редактора в котором открыт *.lua скрипт.
AltF5 и ShiftF9 - исключение, они для области Common (только во время отладки).
Клавиатурные сочетания аналогичны имеющимся в IDE (кроме CtrlF5 и AltF5).
Большая часть макросов предназначена для редактора в котором открыт *.lua скрипт.
AltF5 и ShiftF9 - исключение, они для области Common (только во время отладки).
- CtrlF5 - разрешить/запретить отладку корутин.
Необходимо для того, чтобы отлаживать макросы.
После изменения макросы будут перезагружены.
Альтернатива: вручную добавить в макросrequire"mobdebug".on()
- F5 - подключиться к отладчику (начать отладку),
require"mobdebug".start()
- ShiftF5 - отключиться от отладчика (завершить отладку),
require"mobdebug".done()
- AltF5 - (временно) выключить/включить отладку не отключаясь от отладчика,
require"mobdebug".off()
.
Может быть полезно, т.к. отладка существенно замедляет выполнение кода. - ShiftF9 - прервать выполнение текущего скрипта и перейти в IDE.
Внимание: для работы F9 и ShiftF9 важно чтобы папка проектаZBS.projectroot
(устанавливаемая в _macroinit.lua) совпадала с той, что назначена в IDE. - F9 - установить/снять точку останова.
Точки останова можно менять в любой момент, но работают (естественно) только во время отладки.
Внимание: точки установленные/снятые в редакторе фара (пока?) не отображаются в IDE.
Данный фрагмент необходимо использовать вместо того что приведён в шапке темы
- package.nounload.mobdebug = true
- if not ZBS then
- local cocreate = coroutine.create
- _G.ZBS = {}
- ZBS.cocreate = cocreate
- ZBS.cocreate_dbg = function(f, ...)
- return cocreate(function(...)
- if ZBS and ZBS.on then require"mobdebug".on() end
- return f(...)
- end, ...)
- end
- ZBS.osexit = os.exit
- ZBS.breakpoints = {}
- ZBS.projectroot = win.GetEnv"FARHOME":lower() .."\\"
- else
- coroutine.create = ZBS.debugcoro and ZBS.cocreate_dbg or ZBS.cocreate
- end
GeSHi © Codebox Plus Extension
- local mobdebug = require"mobdebug"
- local function DebugCoro(arg)
- if type(arg)~="boolean" then return ZBS.debugcoro else ZBS.debugcoro = arg end
- end
- local function DebuggerIsAttached(arg)
- if type(arg)~="boolean" then return ZBS.attached else ZBS.attached = arg; ZBS.on = arg end
- end
- local function MessagePopup(msg,title,flags,delay) --private
- local s = far.SaveScreen()
- far.Message(msg,title or "","",flags)
- mf.sleep(delay or 500); far.RestoreScreen(s)
- end
- Macro { description="ZBS: toggle debugging of coroutines (macros will be reloaded)";
- area="Editor"; filemask="*.lua"; key="CtrlF5";
- action=function()
- local msg = ([[Current status: %senabled]]):format(DebugCoro() and "" or "not ")
- local ans = far.Message(msg,"Debugging of coroutines","Enable;&Disable","l")
- if ans~=-1 then
- DebugCoro(ans==1 and true or false)
- if far.MacroLoadAll() then MessagePopup("Macros reloaded","Debugger") end
- end
- end;
- }
- Macro { description="ZBS: attach debugger";
- area="Editor"; filemask="*.lua"; key="F5";
- action=function()
- local coroinfo = DebugCoro() and "" or "\n[Debugging of coroutines not enabled]"
- if DebuggerIsAttached() then
- MessagePopup("Current status: attached"..coroinfo,"Debugger","",1000)
- elseif mobdebug.start() then
- DebuggerIsAttached(true)
- MessagePopup("Attaching..."..coroinfo,"Debugger")
- os.exit = function()
- mobdebug.done(); os.exit = ZBS.osexit
- DebuggerIsAttached(false);
- MessagePopup("Detaching...","Debugger")
- end
- else
- MessagePopup("Server is not available","Debugger","w")
- end
- end;
- }
- Macro { description="ZBS: detach debugger";
- area="Editor"; filemask="*.lua"; key="ShiftF5";
- action=function()
- if DebuggerIsAttached() then
- os.exit()
- else
- MessagePopup("Not attached","Debugger","w")
- end
- end;
- }
- Macro { description="ZBS: debug hook toggle";
- area="Common"; key="AltF5"; priority=60;
- condition=DebuggerIsAttached;
- action=function()
- ZBS.on = not ZBS.on
- local action = ZBS.on and "on" or "off"
- mobdebug[action]()
- MessagePopup("Turning "..action.."...","Debugger")
- end;
- }
- local function norm (name) --!!depends on projectroot
- return name:lower():gsub(ZBS.projectroot,""):gsub("\\","/")
- end
- local function BreakHere(d)
- local info = debug.getinfo(2+(d or 0))
- local name,line = norm(info.source:match"@(.+)"),info.currentline
- mobdebug.setbreakpoint(name,line);
- mf.postmacro(mobdebug.removebreakpoint,name,line)
- end
- Macro { description="ZBS: break execution at next executed line of code";
- area="Common"; key="ShiftF9"; priority=60;
- condition=DebuggerIsAttached;
- action=function() mobdebug.on(); BreakHere() end;
- }
- local bp = ZBS.breakpoints
- Macro { description="ZBS: toggle breakpoint";
- area="Editor";filemask="*.lua"; key="F9";
- action=function()
- local file,line = norm(Editor.FileName),Editor.CurLine
- local action = (bp[file] and bp[file][line]) and "remove" or "set"
- bp[file] = bp[file] or {}
- bp[file][line] = action=="set"
- mobdebug[action.."breakpoint"](file,line)
- MessagePopup("Breakpoint "..action,"Debugger")
- end;
- }
GeSHi © Codebox Plus Extension
Update: новая версия тут: http://forum.farmanager.com/viewtopic.p ... 04#p117004