CoronaSDK and SublimeText2 Build System

[Update May 15, 2013 –  Fixed launcher for osx and windows]

I’ve recently been trying out different editors as I can see the end of the road for TextMate from where I’m sitting.   I really wanted to be super-awesome and finally learn vi or emacs, but despite several attempts, my brain hasn’t really latched onto them like it did when TM came onto the scene.

Now there’s SublimeText 2 (in beta) which is starting to be the editor that TM wanted to be when it grew up.  There’s still a lot of funky things with it, but I can see the potential.  Not to mention it’s cross platform like the ancient gods vi and emacs.   I suppose that’s really just icing on the cake because I rarely leave my home platform for reasons other than duress (Windows) or curiosity (Linux).

The one thing I really missed from TM was the ability to launch the CoronaSDK simulator from the editor.   It’s fantastic to be able to edit a file and hit a button and have it fire up the simulator and then start reloading the simulator each time the file changes. (actually the simulator does that work for you)  I took a look at the Corona bundle for TM and found quite a few lines of AppleScript that are doing the work (i kid not).

tl;dr

In Sublime, select “Tools > Build System > New Build System…”

This opens up a new text file.  Copy and paste this into it:

{
"osx" : {
"cmd": ["/Applications/CoronaSDK/Corona Simulator.app/Contents/MacOS/Corona Simulator","main.lua"]
},
"windows" : {
"cmd": ["C:\Program Files\Corona Labs\Corona SDK\Corona Simulator.exe","main.lua"]
},
"file_regex": "^[ ]*File "(...*?)", line ([0-9]*)",
"working_dir": "${project_path:${folder}}",
"selector": "source.lua"
}

By setting the working_dir to the project folder and specifying ‘main.lua’ as the file, you can launch the simulator for a project no matter what file you happen to be looking at (or in what subfolder).

Save the file as “CoronaSDK.sublime-build”

  1. Go to your Corona project
  2. Open a file to edit
  3. Select  Tools > Build System > CoronaSDK
  4. Press Command-B
  5. profit!

For Reference,  custom build system files are usually stored in the following locations:

OS X: ~/Library/Application Support/Sublime Text 2/Packages/User

Windows: %APPDATA%/Sublime Text 2/Packages/User

6 Comments

  1. WOW! Just Amazing tip!

    I use ST2 and love it but now – hahaha, more than Awesome to get it running like that.

    Thank you for sharing.

    Cheers,
    Rodrigo – RSCdev.net
    Follow me: @RSCdev

  2. Doesn’t seem to work with folders that have spaces in them. any way to get around this? (apart from removing the spaces of course ;-))

  3. I tried either
    “cmd”: [“/Applications/CoronaSDK/simulator”, “main.lua”]
    or
    “cmd”: [“/Applications/CoronaSDK/simulator”,”$file_path”],
    “selector”: “source.lua”

    But, with both I have the same trouble : with +B, a new instance of the simulator is launched, I can’t just get an update to the simulator (like in textmate), it eventually leads totons of simulator opened and it’s just unusable.

    Thx for any hints.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.