Löve debugging with ZeroBrane Studio

General discussion about LÖVE, Lua, game development, puns, and unicorns.
paulclinger
Party member
Posts: 227
Joined: Thu Jun 28, 2012 8:46 pm

Re: Löve debugging with ZeroBrane Studio

Post by paulclinger »

WarpEnterprises wrote:Thanks very much for ZBS, I have some points I can't get to work as I would expect:
Apologies for the delay in response; I missed this message...

> * when using Project->Start debugging, it always stops at the ...require("mobdebug").start()... line, although there is no breakpoint there.

Yes, this is a default, but you can add "debugger.runonstart = true" to cfg/user.lua to make it not stop on the start() call.

> * I can't toggle a breakpoint while love is running - is this intentionally?

Yes; for now you can only change a breakpoint when a debugger is paused.

> * is there a keyboard shortcut for adding a selected text to the watch window?

Not a shortcut, but you can use right click and select "Evaluate in Console".

If you want to have a shortcut, you can add something like this to the cfg/user.lua file:

Code: Select all

local G = ... -- this now points to the global environment in the script
local ide, wx, TR, ID = G.ide, G.wx, G.TR, G.ID
local postinit = ide.app.postinit
ide.app.postinit = function()
  if postinit then postinit() end
  local menu = ide.frame.menuBar:GetMenu(ide.frame.menuBar:FindMenu(TR("&Edit")))
  menu:Append(ID "eval", "Evaluate in Console\tCtrl-E")
  ide.frame:Connect(ID "eval", wx.wxEVT_COMMAND_MENU_SELECTED,
    function () ShellExecuteCode(GetEditor():GetSelectedText()) end)
  ide.frame:Connect(ID "eval", wx.wxEVT_UPDATE_UI,
    function (event) event:Enable(GetEditor() and #GetEditor():GetSelectedText() > 0) end)
end
It will set Ctrl-E as a shortcut for evaluating currently selected fragment (and will add a menu item to the Edit menu).

Paul.
Bobbias
Prole
Posts: 36
Joined: Sat Jun 29, 2013 1:26 pm

Re: Löve debugging with ZeroBrane Studio

Post by Bobbias »

I decided to check this out since I've been using notepad++ and dragging my project directory onto a shortcut to love for testing... Unfortunately I can't seem to debug my code in it... I've added

Code: Select all

if arg[#arg] == "-debug" then require("mobdebug").start() end
to my love.load function and set ZBS to use the Love2d interpreter, ZBS correctly locates love.exe and spawns a process with the correct command line, but I never see a window appear, and ZBS only allows me to stop the process.

Am I missing something here? Is there something wrong with ZBS that hasn't been discussed here?
paulclinger
Party member
Posts: 227
Joined: Thu Jun 28, 2012 8:46 pm

Re: Löve debugging with ZeroBrane Studio

Post by paulclinger »

Bobbias wrote:I decided to check this out since I've been using notepad++ and dragging my project directory onto a shortcut to love for testing... Unfortunately I can't seem to debug my code in it... I've added

Code: Select all

if arg[#arg] == "-debug" then require("mobdebug").start() end
to my love.load function and set ZBS to use the Love2d interpreter, ZBS correctly locates love.exe and spawns a process with the correct command line, but I never see a window appear, and ZBS only allows me to stop the process.
@Bobbias, everything looks correct based on your description (one small thing is that I'd add 'arg and' to 'if arg and arg[#arg] == "-debug"...' ).

Are you trying "Run" or "Debug" your project? Can you try running the command that ZBS executes from the command line to see if that works? You can see the command shown in the Output window as Program starting as '....'. Can you try debugging one of the love projects that comes with ZBS to see if it works for you? There are three simple projects in myprograms/love2d-samples/ folder. Paul.
bobeff
Prole
Posts: 2
Joined: Sat Dec 28, 2013 4:39 pm

Re: Löve debugging with ZeroBrane Studio

Post by bobeff »

Hi,

I started to use ZeroBrane Studio for Löve2d developement, but I had faced the following problem. Is it possible to view output console activated with "--console" option from command line when the program is started from ZeroBrane or the output to be redirected to some of the ZeroBrane windows?
paulclinger
Party member
Posts: 227
Joined: Thu Jun 28, 2012 8:46 pm

Re: Löve debugging with ZeroBrane Studio

Post by paulclinger »

> Is it possible to view output console activated with "--console" option from command line when the program is started from ZeroBrane or the output to be redirected to some of the ZeroBrane windows?

I'm working on adding support for command line options, so it will be possible to add --console option to love2d launch command. As far as I understand, this should have the same effect as adding t.console = true to conf.lua, but for some reason I don't see the output redirected to ZBS (this is using 0.9.0). I'm checking on that...

Another alternative with ZBS is to set debugger.redirect = "c" in ZBS config file. This will make anything you "print" from the love2d script to appear in the Output window. Just make sure you don't print something every frame ;).

One advantage of this remote printing is that it pretty-prints its arguments, which allows you to do "print(mytable)" and get mytable content as the output.

ZBS also provides two plugins that use remote printing and may be helpful in debugging your application. One allows you to see watches in real-time; for example, your application may show its memory utilization (or any other data) every second and the plugin makes this information appear as one of the watches and updates this information in real-time while your application is running (under the debugger). The plugin and description is available here. Keep in mind that it's likely to have impact on performance as the messages are sent over TCP for every "print", so you probably don't want to print something on every frame.

The second plugin allows you to save remote output to a file (useful for later analysis). It also truncates the output shown in the output window to specific number of lines, which allows you to process long outputs while limiting memory impact. This plugin is available here.
Last edited by paulclinger on Mon Mar 03, 2014 8:10 pm, edited 1 time in total.
bobeff
Prole
Posts: 2
Joined: Sat Dec 28, 2013 4:39 pm

Re: Löve debugging with ZeroBrane Studio

Post by bobeff »

@paulclinger Thanks for the comprehensive response. The option with debugger.redirect = "c" works for me.
User avatar
Jack Dandy
Prole
Posts: 49
Joined: Mon Sep 08, 2014 4:26 pm

Re: Löve debugging with ZeroBrane Studio

Post by Jack Dandy »

Hey, sorry for the resurrection, but I'm trying to figure something out.
Entering the game with the debugging mode on can REALLY cause stuff to slow down.

Is there a way to use the print function to print stuff to ZBS' output console in real-time? I tried it, but it only updates after I close the game.

Basically, I want to do what they show in here:
https://youtu.be/eMUYRIh8g0c?list=PL924 ... 4D91&t=305
paulclinger
Party member
Posts: 227
Joined: Thu Jun 28, 2012 8:46 pm

Re: Löve debugging with ZeroBrane Studio

Post by paulclinger »

Jack Dandy wrote:Is there a way to use the print function to print stuff to ZBS' output console in real-time? I tried it, but it only updates after I close the game
Yes, it should print right away if you add "io.stdout:setvbuf('no')" to your script; see this FAQ item: http://studio.zerobrane.com/doc-faq#why ... put-window

Paul.
User avatar
Jack Dandy
Prole
Posts: 49
Joined: Mon Sep 08, 2014 4:26 pm

Re: Löve debugging with ZeroBrane Studio

Post by Jack Dandy »

Oh, sweet! Thanks.
And one last thing, seeing as you're here and all: Is there a way to activate the REAL debugger only for certain parts of the code?
Running the game in full debugging mode is slow as mollasses! :?
paulclinger
Party member
Posts: 227
Joined: Thu Jun 28, 2012 8:46 pm

Re: Löve debugging with ZeroBrane Studio

Post by paulclinger »

Jack Dandy wrote:Is there a way to activate the REAL debugger only for certain parts of the code?
Sure; see this forum post for details and related links: viewtopic.php?f=4&t=78401&start=360#p186060
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 5 guests