What's the idea behind the LiveAPI callback?

    May 09 2012 | 7:53 pm
    It looks like the callback function is passed a string as its only argument, combining the property and the value separated with a comma.
    This seems very odd to me. Why is it like that and not a callback with 2 arguments? If you want to act on the values you first have to parse the thing...?
    Here are my findings. If you just print it it looks like 2 values because the post function interprets the comma, but if you print the type of the argument or convert the js arguments object to string you see that its actually an object:
    This is my callback:
    function onChange(v){ post("Live api path/property change:", v, "n"); post("type", typeof v, "n"); post("argments", argumentsToString(arguments), "n"); }
    I created the argumentsToString function to concat js function arguments into a string:
    function argumentsToString(v){ // convert arguments object to real array var args = Array.prototype.slice.call(v); var str = args.join(" "); return str; }
    This is the output in the max window:
    Live api path/property change: playing_slot_index 3 type object argments playing_slot_index,3
    I don't know what to think of that, but it seems at least a little weird.

    • May 09 2012 | 8:58 pm
      Upon further inspection I realize that the callback function argument appears to be just the same as what the "arguments" object is to all functions. It's an object type, but then sort of an array, but not really a real array, and you convert it to a proper array by means of:
      var args = Array.prototype.slice.call(v); var arg1 = args[0]; var arg2 = args[1];
      I can hardly imagine it's meant to be like this.