ricardoquesada/jsbindings — pull request #3 by funkaster (2012-11-28 01:35:37+00:00)
Title: debugger, yay!

Most of the changes here are for supporting the debugger compartment. The debugger compartment is only created when you call `[[JSBCore sharedInstance] enableDebugger]`.

The js entry point should be similar to this in order to test for debugger:

```javascript
var files = ['cc.main.js'];
if (typeof startDebugger !== "undefined") {
startDebugger(this, files, 'run()');
} else {
for (var i in files) {
require(files[i]);
}
run();
}
```
Here, `cc.main.js` is the real entry point, but we need this in order for the debugger to load the code in the debugged compartment :)

In the AppDelegate.m, the only thing that should change is the new `enableDebugger` call:

```objective-c
[[JSBCore sharedInstance] enableDebugger];
[[JSBCore sharedInstance] runScript:@"main.js"];
```

If you want to disable the debugger, then just comment that line.

The debugger client is the same one that we use in cocos2d-x:

https://raw.github.com/funkaster/cxx-generator/master/targets/spidermonkey/common/dbg_client.rb

You can download that, put it in your project root (next to the xcode project) and add the following script as a pre-action to the "Run" scheme:

```sh
TERMINAL=/Applications/Utilities/Terminal.app

echo "will run debugger"
open -a ${TERMINAL} "${PROJECT_DIR}/dbg_client.rb"
```

The debugger client is using ruby + ncurses. If you don't have ncurses (you can easily install it with `sudo gem install ncurses`), it will fallback to ruby + readline, which is installed in mac os x by default.