Page 1 of 1

Sublime text - is it possible to have live console output?

Posted: Thu Jun 13, 2013 11:39 am
by Johannes
Here's a quick question for any Sublime Text 2 users


For my Löve projects I'm using this build script:

Code: Select all

{
	"selector": "source.lua",
	"cmd": ["/Applications/love.app/Contents/MacOS/love", "$filepath"]
}
(this is for mac of course, you can check this page on the wiki for the corresponding windows script)

It works great, but I noticed that when I use print() in my code I don't see the output until I've closed the löve.app window.

So for example, when I run the simple code:

Code: Select all

function love.load()
	love.graphics.setColor(255,255,255,255)
	love.graphics.print(_VERSION, 100, 100)

	for var = 0, 10, 1 do
		print("test: " .. var)
	end
end
Which displays the Lua version in the Löve.app window and outputs the following in the sublime text console:

Code: Select all

test: 0
test: 1
test: 2
test: 3
test: 4
test: 5
test: 6
test: 7
test: 8
test: 9
test: 10
[Finished in 2.9s]
but not until I actually closed the window (which as you can see there took me 2.9 seconds)

When I run the program manually from the terminal or when using my script file the terminal shows the print output live as it happens:
iI3hUHf.png
iI3hUHf.png (38.69 KiB) Viewed 499 times

Is there a way to make the output display live in sublime text 2 as well?

Re: Sublime text - is it possible to have live console outpu

Posted: Thu Jun 13, 2013 11:46 am
by Johannes
Ah, I found the answer on Stack Overflow

You can make the output display live by adding the following code in your main.lua file:

Code: Select all

io.stdout:setvbuf("no")

Re: Sublime text - is it possible to have live console outpu

Posted: Mon Jun 17, 2013 9:14 am
by verilog
Interesting, I'll make sure to check this out, thanks for sharing! :D

Re: Sublime text - is it possible to have live console outpu

Posted: Mon Jun 17, 2013 9:19 am
by Philbywhizz
That's a very handy tip

Thanks! :awesome:

Re: Sublime text - is it possible to have live console outpu

Posted: Tue Jun 18, 2013 3:38 am
by scutheotaku
I'm using Sublime Text 2 and am getting "live" console output from LOVE just fine, and I don't have to add anything to my main.lua or do anything else special.

Here is my build script (I'm on Windows):

Code: Select all

{
    "folders": [
        {
            "path": "./"
        }
    ], 
    "build_systems": [
        {
            "cmd": [
                "love2d", 
                "--console", 
                "$project_path"
            ], 
            "name": "LOVE", 
            "target": "run_love2d"
        }, 
        {
            "cmd": [
                "love2d_jit_dll", 
                "$project_path"
            ], 
            "name": "LOVE JIT Dll", 
            "target": "run_love2d"
        }
    ]
}