I've developed a really simple console library that you can use in pretty much anything. It's inspired by WoW's console and is toggled with the ~ key (though you can change it easily).
console.lua: http://paste2.org/zYhxXOXD
Usage:
1. Copy console.lua to your project's folder.
2. Tweak the options at the top to whatever tickles your fancy.
3. Add require "console" to the top of main.lua.
4. Whenever you want to log something, simply use console.log(msg) where msg is anything (it's automatically converted to a string so don't worry about non-string types).
5. If you don't want to have to call console.load()/.draw()/.keypressed()/.update() then simply call console.stealth() at the bottom of main and it will automatically hook those into your program.
Example 1 (hello world):
Code: Select all
require "console"
function love.load()
console.log("Hello world from the console!")
end
console.stealth()
Code: Select all
require "console"
local timer = 0
local counter = 1
function love.update(dt)
if timer < 1 then
timer = timer + dt
return
else
timer = 0
end
console.log(counter)
counter = counter + 1
end
function love.keypressed(key)
if key == "tab" then
console.load()
counter = 1
end
end
function love.draw()
love.graphics.setColor(255, 50, 50)
love.graphics.rectangle("fill", 30, 30, 740, 540)
love.graphics.setColor(0, 0, 0)
love.graphics.print("Press TAB to reset the console!", 40, 540)
end
console.stealth()
Code: Select all
require "console"
function love.load()
console.load()
console.log("Hello world from the console!")
end
function love.update(dt)
console.update(dt)
end
function love.keypressed(key)
console.keypressed(key)
end
function love.draw()
console.draw()
end