Donut - simplified debug message control system

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Kasoki
Prole
Posts: 4
Joined: Sun Feb 19, 2012 7:19 am
Location: Germany

Donut - simplified debug message control system

Post by Kasoki »

Hey,

I developed a little library for debug messages. Why? I hate writing the same code multiple times, so i made this library. Probably there is no need for this but i still release it.

What is Donut?

Donut is a simplified debug message control system for LÖVE

Debug message control system? wth???

You're able to add debug messages like this:

Image

Supported languages
  • Lua
  • MoonScript
Usage (Lua)

Code: Select all

require("donut")

function love.load()
	debug = Donut.init(10, 10)
	fps = debug.add("FPS")
	random = debug.add("Random")
end

function love.update(dt)
	debug.update(fps, love.timer.getFPS())
	debug.update(random, math.random(0, 100))
end

function love.keypressed(key, unicode)
	if key == "s" then -- show/hide with "s"
		debug.toggle()
	end
end

function love.draw()
	debug.draw()
	-- you could also use debug.draw(xoffset, yoffset) to move the message if you're using a cam
end
Usage (MoonScript)

Code: Select all

require "donut"

love.load = ->
	export debug = Donut(10, 10)
	export fps = debug\add "FPS"
	export random = debug\add "Random"

love.update = (dt) ->
	debug\update fps, love.timer.getFPS()
	debug\update random, math.random(0, 100)
	""

love.keypressed = (key, unicode) ->
	debug\toggle if key == "s"
	""

love.draw = ->
	debug\draw 0, 0
Documentation

Coming soon...

License

Donut is licensed under the terms of GNU Lesser General Public License v3.

Download
Sourcecode
See Also
Last edited by Kasoki on Sat Mar 10, 2012 2:01 am, edited 4 times in total.
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: Donut - simplified debug message control system

Post by Ellohir »

Simple... yet useful. Looks nice.
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Donut - simplified debug message control system

Post by thelinx »

Two minor issues:
- Use require("donut"), not require("donut.lua").
- Return a table containing your module's functions, don't create a global.
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: Donut - simplified debug message control system

Post by MarekkPie »

Look nice. I'll have to try it out.

Shouldn't it be called like Rimjob or something to work with the Libraries naming theme?
User avatar
Kasoki
Prole
Posts: 4
Joined: Sun Feb 19, 2012 7:19 am
Location: Germany

Re: Donut - simplified debug message control system

Post by Kasoki »

MarekkPie wrote:Look nice. I'll have to try it out.

Shouldn't it be called like Rimjob or something to work with the Libraries naming theme?
I chose Donut because of 2 reasons:

1. It starts with a "D" like debug
2. And i thought the name would be perfect for a library called LÖVE. Donuts are lövely too! ;D
thelinx wrote:Two minor issues:
- Use require("donut"), not require("donut.lua").
Done, but why is that so? I'm not a lua-guy^^
thelinx wrote:- Return a table containing your module's functions, don't create a global.
I wanted to make something like that:

Code: Select all

require("donut")

function love.load()
	debug = Donut.init(10, 10)
	fps = debug.add("FPS")
	random = debug.add("Random")
end

function love.update(dt)
	fps.update(love.timer.getFPS())
	random.update(math.random(0, 100))
end

function love.draw()
	debug.draw()
end
But if I would make it like that then, I would probably lose the one-line draw method. There is a possibility to make it like in the snippet but this would probably make the code inside donut.lua really ugly.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Donut - simplified debug message control system

Post by Robin »

Kasoki wrote:
thelinx wrote:Two minor issues:
- Use require("donut"), not require("donut.lua").
Done, but why is that so? I'm not a lua-guy^^
That's because require thinks in terms of modules, not files. Just like in Java, or say Python:

Code: Select all

import this
What programming language are you most familiar with? If it's not C/C++, chances are it uses a module-based thingy rather than a file-based thingy.
Help us help you: attach a .love.
User avatar
Kasoki
Prole
Posts: 4
Joined: Sun Feb 19, 2012 7:19 am
Location: Germany

Re: Donut - simplified debug message control system

Post by Kasoki »

Robin wrote:
Kasoki wrote:
thelinx wrote:Two minor issues:
- Use require("donut"), not require("donut.lua").
Done, but why is that so? I'm not a lua-guy^^
That's because require thinks in terms of modules, not files. Just like in Java, or say Python:

Code: Select all

import this
What programming language are you most familiar with? If it's not C/C++, chances are it uses a module-based thingy rather than a file-based thingy.
Thanks, I thought Lua is rather file-based. I read the wrong tutorial, I guess.

I'm by the way a python developer ;).
User avatar
Kasoki
Prole
Posts: 4
Joined: Sun Feb 19, 2012 7:19 am
Location: Germany

Re: Donut - simplified debug message control system

Post by Kasoki »

Donut now also supports MoonScript. I thought it might be worth mentioning :D.
User avatar
trubblegum
Party member
Posts: 192
Joined: Wed Feb 22, 2012 10:40 pm

Re: Donut - simplified debug message control system

Post by trubblegum »

I think this would be a great little time-saver for a lot of folks.

Here's how the one line thing works ..

in donut.lua :

Code: Select all

local donut = {
-- code here
}
return donut
in main.lua :

Code: Select all

debug = require('donut') -- a global conaining the value returned by donut.lua, a donut
no need for donut.init() because require returned a fully-formed donut, and I can still have a global donut, if I'm making a game about a donut :)
and since debug is a fully-formed donut, debug.draw() (more likely debug:draw()) is the donut's draw function

if you want to allow several instances of your donut (which personally, I think all libs should try to do) you can do something like :

Code: Select all

local donut = {
   new = function(this)
      local new = {
         -- variables here, so they're not referenced
      }
      return setmetatable(new, {__index = this})
   end
-- functions here, so they're inherited
}
return donut
Edit : You probably just want to return donut at the bottom of donut.lua, not an instance of donut, since it will be the master class anyway. That way I can use it right out of the box, or create instances if I choose.

Now I can have several debug objects, each tracking different objects, and positioned independently, like so :

Code: Select all

donut = require('donut')
debugload = donut:new()
debugupdate = donut:new()
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Donut - simplified debug message control system

Post by Kingdaro »

so wait

this "moonscript"

it's a scripting language made with a scripting language made with a scripting language?
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests