Paul Robertson's words, punctuated

Thoughts on development, user-centered design, code, etc. by Paul Robertson

MTASC syntax checking in PrimalScript

Like many others, I have been spending some time working with MTASC over the past few months. MTASC is a full featured ActionScript compiler, although frankly my favorite part of it is that it provides much stricter syntax checking than Flash’s built-in compiler (especially with the optional -strict mode) meaning many more bugs found at or before compile time and many fewer problems to find later. In addition, it can be used just as a syntax checker without actually creating an output .swf file.

The easiest “integrated” way to use this checking is by using the ActionScript plugin for Eclipse, which has an integrated MTASC panel and options. However, I have recently been trying out PrimalScript and wanted to see if I could get similar functionality working.

A couple of days ago Keith Peters wrote about using MTASC as a compiler from PrimalScript. The approach he describes involves writing a batch (.bat) file and having PrimalScript call that file. That approach (at least as he describes it) requires setting up the .bat file for each project, and is really tailored toward a final compilation rather than a simple syntax check. Of course, one definite advantage of the .bat file approach is that you could theoretically use other tools in addition to MTASC, such as passing your code through a preprocessor before passing it along to MTASC. Of course, this would have some extra complexity to it (e.g. the preprocessor output would have to be saved to a separate file to be processed by MTASC, which would in turn cause the “click on the error to be taken to the specific line of code” feature of PrimalScript to break). I still need to think about how to make something like that work well.

My goal as I was trying to integrate MTASC with PrimalScript was to make it so that once the options are set, it works for every project without needing to create a project-specific build file. I’ve actually had this working for several weeks now, so Keith’s post gave me a little motivation to write something up too, especially since it took a bit of trial and error to get it figured out.

So here’s my setup, to use MTASC for ActionScript syntax checking in PrimalScript:

  1. Go to Tools > Options > Environment > Languages > ActionScript
  2. Under “Select a Category” choose “Compile / Syntax check”. By Default, “Script Interpreter” is chosen – this one is intended to be like “Test Movie” in Flash but I actually just wanted a syntax checker (PrimalScript lets you specify both).
  3. In the first text box, enter the path to mtasc.exe
  4. In the “Arguments:” text box, enter the following (all on one line, not separated as I’m showing here):
    -cp “<full path to one classpath (surrounded by quotes)>”
    -cp “<full path to second classpath (surrounded by quotes)>”
    -cp “$ProjectFolder$”
    <any other MTASC options (e.g. I use -msvc -strict)>
    $FileName$
  5. In the “Initial Directory:” text box, enter “$FileDir$” (without quotes)
  6. Check the “Capture output” box

Some important notes:

  • For some reason, if you only specify “Compile/Syntax check” properties (and not “Script Interpreter” properties) then the Syntax check toolbar button/menu option will not be available. You also have to specify a Script Interpreter even if you don’t intend to use it. I just used the same settings that I used for “Compile/Syntax check,” but I will probably try setting it up to use an approach like Keith’s in the future.
  • You can put as many “-cp” ClassPath arguments as you want – I have just a single class path location where I keep all my non-project-specific code, just to simplify, but you don’t have to do that of course.
  • You must include the “$ProjectFolder$” classpath so that MTASC can find project-specific classes in your project.
  • All the -cp arguments must be surrounded by quotes, but the $FileName$ argument must not be

If you have any questions or other ideas, I’d love to hear about them too.

Comments