Created
September 14, 2011 13:35
-
-
Save gotascii/1216556 to your computer and use it in GitHub Desktop.
Node in Max/MSP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compile the coffee in bare joined mode. | |
{exec, spawn} = require 'child_process' | |
fs = require 'fs' | |
util = require 'util' | |
print = (data) -> | |
console.log data.trimRight() | |
task 'build', 'Compile Coffeescript to Javascript', -> | |
exec 'mkdir -p lib && coffee --bare --output lib --compile --join weird.js src/*.coffee' | |
task 'clean', 'Remove generated Javascripts', -> | |
exec 'rm -fr lib' | |
task 'test', 'Run the tests', -> | |
vows = exec "vows --spec test/*test*" | |
vows.stdout.on 'data', print | |
vows.stderr.on 'data', print |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test/helper.coffee | |
# Create globals for the classes under test. | |
global.util = require 'util' | |
global.assert = require 'assert' | |
require '../src/array' | |
global.World = require('../src/world').World | |
global.Inspector = require('../src/inspector').Inspector | |
global.Lseq = require('../src/lseq').Lseq | |
vows = require 'vows' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
w = new World 16, 8 | |
gw = new Global "world" | |
@bang = -> | |
post w.cells.length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# src/world.coffee | |
# Define classes as top level vars. | |
@World = class | |
constructor: (@lseq, @cells) -> | |
unless @cells? | |
@cells = @generateCells() | |
@reset() | |
generateCells: -> | |
len = @length() - 1 | |
@lseq.toCoords(i) for i in [0..len] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test/world_test.coffee | |
# Test the globals defined in helper.coffee. | |
require './helper' | |
test module, 'World', | |
'constructor with an lseq and no provided cells': | |
topic: -> | |
@lseq = new Lseq({x:0, y:0}, 2, 2) | |
@world = new World @lseq | |
'has an lseq': -> | |
@world.lseq.should eq @lseq | |
'has an array of cells with 0 state': -> | |
cells = [ | |
{x: 0, y: 0, state: 0}, | |
{x: 1, y: 0, state: 0}, | |
{x: 0, y: 1, state: 0}, | |
{x: 1, y: 1, state: 0} | |
] | |
@world.cells.should deq cells |
I've been stubbing out the Max API using a little mock/stub library I put together, but you've got the basic gist. I've been testing my own class' functionality to make sure those work correctly and then using the resulting JS inside of Max. If you were interested in writing tests that exercised the Max API itself, I would give Rhino a shot. If you are able to get Rhino running inside of Max let me know because I think that could be awesome.
I talked to some c74 guys when i speak at http://code-control.com and showed them coffee script and talked about Node.
Lets see what they will do about it ( :
Hope they enjoyed the ideas, and pay me a beer after they get millionare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, so you're just writing tested javascript that doesn't make use of the Max API and using it in Max then?