TIP : Edit your Corona Code with autocomplete and syntax highlighting without spending a cent extra

Hi,
Most new comers will wonder how to write their code, what editor to use and how to get syntax highlighting and autocomplete.

Hidden (I say hidden 'coz I just read that today). I downloaded the file from http://www.capgo.com/Resources/SoftwareDev/LuaXcode3SyntaxColor.zip and unzipped it and copied the files to the ~/Library/Application Support/Developer/Shared/Xcode/Specifications/ directory. You might have to create the directory called Specifications before you can copy the files there.

What I also did was add a few more commands. These were to test, like display.newImage, display.newRect, etc.

Then I started XCode and with NO project, just chose a blank file, called it main.lua and started to type in some code…

Voila, Syntax Highlighting, press ESC, code completion… WOW!! Amazing, now the process of development can be more fun and faster than working with TextEdit or TextWrangler.

I also got my hands on Corona Project Manager yesterday, add this to your repertoire of tools and you are all set.

I shall try to add the Corona keywords and share them with you here.

I found this to be the easiest and more intuitive way to code for Corona. Now if there was a way to compile and run from xcode itself.

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3775 reply_id: 303775[/import]

Got most of the keywords typed in, trying to see if I can modify them to show up in different colours and be identified with the Corona Syntax.

Lua syntax of

function = myFunction() is recognized, but the Corona syntax or the relaxed form

myFunction = function() is not recognized and hence code folding does not happen.

Due to this even the while do … end are not code folded, so a bit of an issue.

Anyone that has experience with XCode xclangspec wanna help?

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3775 reply_id: 11485[/import]

I cannot find this path on my MAC Pro ~/Library/Application Support/Developer/Shared/Xcode/Specifications/

how can i retch that path? i tried to allocate that folder but its not there

Thanks [import]uid: 11038 topic_id: 3775 reply_id: 11636[/import]

In case you did not read the first post

>>>You might have to create the directory called Specifications before you can copy the files there.
Do you have xCode installed? If so, then the path up to ~/Library/Application Support/Developer/Shared/Xcode/ is already there.

and ~ is equivalent to your home dir (/Users//)

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3775 reply_id: 11650[/import]

Last week got tied up in other stuff, forgot to upload this file.

Please feel free to modify as you seem fit, if you make something nifty, please share it back with all.

File here

cheers,

Jayant C Vama [import]uid: 3826 topic_id: 3775 reply_id: 12207[/import]

Matthew Pringle wrote a forum post on how to Get Xcode to build directly with Corona

http://developer.anscamobile.com/forum/2010/03/02/get-xcode-build-directly-corona-0

Hope this helps

Thanks for xcode syntax coloring for Corona.

Carlos [import]uid: 24 topic_id: 3775 reply_id: 12323[/import]

I took the text from Matthew Pringle’s text at the forum in the link above and created a PDF that new users can follow to use XCode as the default editor for Corona and use Syntax Highlighting.

The document can be found here
http://iphone.jayantvarma.id.au/files/XCodeAsEditor.pdf

Hope that you find it useful

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3775 reply_id: 12359[/import]

V Nice indeed

Can you/we post the doc in our resource code-exchange page?

Carlos [import]uid: 24 topic_id: 3775 reply_id: 12365[/import]

Hi Carlos,
Done. did not know that had to touch 50 words.

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3775 reply_id: 12385[/import]

That’s great.

I wonder if there’s a clever way to get either the simulator to run or the debugger without having to change the build tool [import]uid: 9371 topic_id: 3775 reply_id: 12430[/import]

I followed everyting, copied files, restarted Xcode, hilighting works but autocomplete still don’t work T_T
Any help please… I really need it to work.

SOLVED – Autocomplete works after pressing return and start working with the second line of the code… how nonsense. [import]uid: 35267 topic_id: 3775 reply_id: 21889[/import]

Hello

I don’t know if this is commen knowledge, but there is also a possibility to do custom user scripts for xcode. For example a script that (un)comments selected text or inserts a module template.

Here is an example of what you need to do to have a lua (un)comments shortcut:

  1. Go to the user script menu in XCode (the one with the weird sign)
  2. Choose “Edit User Scripts”. Now a window called “Edit User Scripts” will pop up.
  3. Click the plus sign in lower left corner. Choose “New Submenu” from pop-up menu.
  4. Name the submenu “Corona”
  5. Click the plus sign in lower left corner again and choose “New Shell Script” and name it “Un/Comment”.
  6. Copy and paste this code to the script code box :

//////////////////////////////////////////////

#! /usr/bin/perl -w

my $outputString = “”;
my $cCmt = “–”;

my $fileString = <%%%{PBXHeadText}%%%
HEADTEXT

my $commentString = $cCmt;

my @selection = ;

if (!@selection) {
push @selection, “”;
};

my $firstLineOfSelection = $selection[0];
my $addingCommentsString = 1;
if ($firstLineOfSelection =~ /^$commentString/) {
$addingCommentsString = 0;
}

foreach my $line (@selection) {
if ($addingCommentsString == 1) {
$outputString .= $commentString.$line;
} else {
$line =~ s/^$commentString//;
$outputString .= $line;
}
}

print “%%%{PBXSelection}%%%”;
print $outputString;
print “%%%{PBXSelection}%%%”;

///////////////////////////////////////

7. Set the pop up bars to these values:
Input: Selection
Directory: Home Directory
Output: Replace Selection
Errors: Display in Alert

8. Choose a shortcut for your (un)comment script in the “Menu and item” list. (I use cmd -)

Now you have a lua style (un)commenting shortcut.

Here is another script example inserting a module template:

///////////////////////////////////////////
use strict;

print “module(…, package.seeall)\n”;
print “\n”;
print “–constructor------------------------------\n”;
print “\n”;
print “function new()\n”;
print " local obj = display.newGroup()\n";
print ’ obj.name = “%%%{PBXSelection}%%%%%%{PBXSelection}%%%”’;
print “\n”;
print “\n”;
print “–destructor-------------------------------\n”;
print “\n”;
print " function obj:remove()\n";
print ’ print( “removing: " … obj.name)’;
print “\n”;
print " cleanGroup( self )\n”;
print " self = nil\n";
print " end\n";
print “\n”;
print " return obj\n";
print “end\n”;

exit 0;

////////////////////////////////////

it is fairly easy to do these script. You can copy the scripts that already in xcode and modify them. It improved my workflow a lot.

Hope this is helpful. If you do any cool scripts please post them.


[import]uid: 13632 topic_id: 3775 reply_id: 27770[/import]

@ojnab,
yes, not only that you can use a variety of languages like Perl, Python, Apple Script and Shell Script to write these scripts to manipulate xcode.

cheers, [import]uid: 3826 topic_id: 3775 reply_id: 27772[/import]