Parsing arguments and attributes

I’ve seen this mentioned a few times on the list but have never seen any code that demonstrates it properly (or at least that I could understand). I’ve been playing with javascript in max quite a lot recently so I thought I’d have a go myself.

First you need to place the lh.jsextensions.js file in your Cycling ’74 > jsextensions folder and restart max. Then put the lh.aa_example.js file somewhere in your search path and fire up the max patch. It should demonstrate how you can query arguments and attributes from inside your javascript file.

You need to define a variable and initialise the aa_parser(), making sure you pass it the this keyword in your global code. You can then use the getargs() and getattr() methods to return arrays of the arguments or specified attributes. There is also the query() method to print everything to the max window. Hopefully the patch will make everything clear.

There are two fairly important things to note: attribute names can only contain letters, numbers and the _underscore_ character (although this could easily be changed) and at the moment attributes not followed by regular jsarguments are completely ignored.

If you do have any questions or problems the let me know. I hope someone else finds it useful.

I’ve fixed this so you don’t have to call the methods to return the arrays of arguments/attributes, you can now access them directly with properties.

To use the example I posted previously, the arguments would be aa.args, and the two attributes would be aa.mode and aa.verbose. You can also access these dynamically with aa[string] where the variable string is either "mode", "verbose" or "args". Obviously this means you cannot name one of your attributes "@args", if you do it will be ignored.

This should make attributes much easier to use. It’s not quite ready but hopefully I’ll post the new code later today.