Skip to content

Commit

Permalink
added doLoop() to replace loop() from Processing API as loop in CS is…
Browse files Browse the repository at this point in the history
… a reserved keyword. .. and added an example to show it.
  • Loading branch information
fjenett committed May 24, 2013
1 parent b409956 commit aca5315
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 25 deletions.
4 changes: 2 additions & 2 deletions lib/build.number
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Mon May 20 13:35:49 CEST 2013
build.number=262
#Fri May 24 23:04:54 CEST 2013
build.number=268
3 changes: 3 additions & 0 deletions readme.md
Expand Up @@ -70,6 +70,9 @@ if img.loaded
See Examples > Basic > Image > ...
Or use requestImage().

**loop() is doLoop()**
"loop" in CoffeeScript is a reserved keyword for the loop control structure, so here in CS mode doLoop() replaces the loop() from the Processing API. I added an example under "Examples -> Language -> LoopNoLoopDoLoop" that shows the use of both.


***How does it work?***

Expand Down
4 changes: 2 additions & 2 deletions release/CoffeeScriptMode.txt
Expand Up @@ -3,5 +3,5 @@ authorList = [Florian Jenett](http://bezier.de/)
url = https://github.com/fjenett/coffeescript-mode-processing
sentence = Adds a CoffeeScript Mode based on Processing.js
paragraph = CoffeeScript Mode is based on JavaScript Mode and runs on top of Processing.js. It runs through a server and inherits the template system from JavaScript mode. CoffeeScript is a functional language that compiles to JavaScript and was created by (Jeremy Ashkenas)[https://github.com/jashkenas/coffee-script].
version = 261
prettyVersion = 0.0.6
version = 267
prettyVersion = 0.0.7
Binary file modified release/CoffeeScriptMode.zip
Binary file not shown.
24 changes: 24 additions & 0 deletions resources/examples/Language/LoopNoLoopDoLoop/LoopNoLoopDoLoop.pde
@@ -0,0 +1,24 @@
###
This example quickly shows you the use of loop, the CoffeeScript control structure and
noLoop() and doLoop() which control playback. Note that "loop()" from Processing API is
"doLoop()" here in CoffeeScript mode as "loop" is a reserved keyword!
###

setup: ->
size 200, 200
noLoop()

draw: ->
background( frameCount % 255 )

[x, y] = [20, 20]
loop
fill x
rect x, y, 20, 20
x += 10
y += 14
break unless y < (height-28)

keyPressed: ->
doLoop()

@@ -0,0 +1,2 @@
coffee.editor.tabs.size=4
mode=de.bezier.mode.coffeescript.CoffeeScriptMode
39 changes: 20 additions & 19 deletions resources/processing-api-min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions resources/processing-api.js
Expand Up @@ -63,7 +63,8 @@ var ADD = ALIGN_CENTER = ALIGN_LEFT = ALIGN_RIGHT = ALPHA = ALPHA_MASK = ALT = A
join =
keyPressed = keyReleased = keyTyped =
lerp = lerpColor = lightFalloff = lightSpecular = lights = line = loadBytes = loadFont = loadImage =
loadMatrix = loadPixels = loadShader = loadShape = loadStrings = loadType = log = loop =
loadMatrix = loadPixels = loadShader = loadShape = loadStrings = loadType = log =
doLoop =
mag = map = match = matchAll = max = millis = min = minute = modelX = modelY = modelZ = month = mouseButton =
mouseClicked = mouseDragged = mouseMoved = mousePressed = mouseReleased =
nf = nfc = nfp = nfs = noClip = noCursor = noFill = noHint = noLights = noLoop = noSmooth = noStroke =
Expand Down Expand Up @@ -375,7 +376,7 @@ var injectProcessingApi = function(processing) {
loadStrings = processing.loadStrings;
loadType = processing.loadType;
log = processing.log;
loop = processing.loop;
doLoop = processing.loop;
mag = processing.mag;
map = processing.map;
match = processing.match;
Expand Down
19 changes: 19 additions & 0 deletions src/de/bezier/mode/coffeescript/CoffeeScriptBuild.java
Expand Up @@ -43,6 +43,9 @@ public class CoffeeScriptBuild extends JavaScriptBuild
private final static String SETUP_REGEX =
"^[\\s]*setup[\\s]*[:][\\s]*->[\\s]*?";

private final static String LOOP_CHECK_REGEX =
"[\\s]+loop[\\s]*\\([\\s]*\\)";

private File binFolder;
private Sketch sketch;
private Mode mode;
Expand Down Expand Up @@ -132,6 +135,22 @@ public boolean build ( File bin ) throws IOException, SketchException
"\n" + bigCode.toString() +
"\n";

// ------------------------------------------
// CHECK FOR loop KEYWORD
// ------------------------------------------

String[] loopMatches = PApplet.match( coffeeCode, LOOP_CHECK_REGEX );
if ( loopMatches != null && loopMatches.length > 0 )
{
Base.showWarning(
"\"loop\" is a CoffeeScript keyword",
"The precompiler found one or more instances of \"loop()\" in your code.\n"+
"If you were intending to use the Processing loop() function there,\n"+
"please change it to \"doLoop()\" as loop is a CoffeeScript keyword.",
null );
return false;
}

// ------------------------------------------
// PRE-COMPILE
// ------------------------------------------
Expand Down

0 comments on commit aca5315

Please sign in to comment.