var repl       = require('repl');
var vm         = require('vm');

module.exports = Repl;
function Repl(client) {
  this._client   = client;
  this._repl     = null;
  this._nodeEval = null;
}

Repl.prototype.resume = function() {
  this._repl = repl.start({
    prompt : 'drone> ',
  });

  this._nodeEval = this._repl.eval;
  this._repl.eval = this._eval.bind(this);

  this._setupAutocomplete();
};

Repl.prototype._setupAutocomplete = function() {
  for (var property in this._client) {
    if (property.substr(0, 1) === '_') {
      // Skip "private" properties
      continue;
    }

    this._repl.context[property] = this._client[property];
  }

  this._repl.context.client = this._client;
};

Repl.prototype._eval = function(code, context, filename, cb) {
  var args = code.match(/[^() \n]+/g);
  if (!args) {
    return this._nodeEval.apply(this._repl, arguments);
  }

  var property = args.shift();
  if (!this._client[property]) {
    return this._nodeEval.apply(this._repl, arguments);
  }

  var type = typeof this._client[property];

  if (type === 'function') {
    try {
      cb(null, this._client[property].apply(this._client, args));
    } catch (err) {
      cb(err);
    }
    return;
  }

  if (args.length > 1) {
    // Don't accept more than 1 argument
    cb(new Error('Cannot set property "' + property + '". Too many arguments.'));
    return;
  }

  if (args.length === 1) {
    // Set a client property
    cb(null, this._client[property] = args[1]);
    return;
  }

  // args.length === 0, return property value
  cb(null, this._client[property]);
};

@@ -319,18 +319,113 @@
 l.eval;%0A
+%0A
   
+// @TODO This does not seem to work for animate('yawShake', 2000), need%0A  // to fix this.%0A  //
 this._re
@@ -686,50 +686,151 @@
     
-this._repl.context%5Bproperty%5D = this._clien
+var value = this._client%5Bproperty%5D;%0A    if (typeof value === 'function') %7B%0A      value = value.bind(this._client);%0A    %7D%0A%0A    this._repl.contex
 t%5Bpr
@@ -832,24 +832,32 @@
 xt%5Bproperty%5D
+ = value
 ;%0A  %7D%0A%0A  thi

Simplify repl