Page 1 of 1

Donut - simplified debug message control system

Posted: Mon Feb 20, 2012 11:49 pm
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

Re: Donut - simplified debug message control system

Posted: Tue Feb 21, 2012 12:18 am
by Ellohir
Simple... yet useful. Looks nice.

Re: Donut - simplified debug message control system

Posted: Tue Feb 21, 2012 12:19 am
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.

Re: Donut - simplified debug message control system

Posted: Tue Feb 21, 2012 11:55 am
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?

Re: Donut - simplified debug message control system

Posted: Fri Feb 24, 2012 12:23 pm
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.

Re: Donut - simplified debug message control system

Posted: Fri Feb 24, 2012 1:32 pm
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.

Re: Donut - simplified debug message control system

Posted: Fri Feb 24, 2012 4:59 pm
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 ;).

Re: Donut - simplified debug message control system

Posted: Sat Mar 10, 2012 2:06 am
by Kasoki
Donut now also supports MoonScript. I thought it might be worth mentioning :D.

Re: Donut - simplified debug message control system

Posted: Sat Mar 10, 2012 11:57 am
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()

Re: Donut - simplified debug message control system

Posted: Sun Mar 11, 2012 2:36 am
by Kingdaro
so wait

this "moonscript"

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