<commit_before># Macchiato #

## About ##

__Macchiato__ is a small and __highly experimental__ PHP library, built on top of the
[SpiderMonkey](http://pecl.php.net/package/spidermonkey) PECL extension, that compiles
[CoffeeScript](http://coffeescript.org/) code to JavaScript, or directly executes it.

Unfortunately the SpiderMonkey PECL extension cannot be considered stable at this point.
Compiling CoffeeScript to JavaScript should not pose any problem, but code execution can
lead to random segmentation fault errors.


## A few examples ##

### Create an instance of Macchiato ###

Macchiato requires the CoffeeScript _client_ compiler library in order to work, so you
must pass a valid path or URI for the JavaScript file to the constructor method:

``` php
<?php
$pathToCoffeeScript = 'coffee-script.js';
$coffee = new Macchiato\CoffeeScript($pathToCoffeeScript);
```

### Compile CoffeeScript to JavaScript ###

You can pass your CoffeeScript code to Macchiato and compile it to JavaScript:

``` php
<?php
var_dump($coffee->compile('square = (x) -> x * x'));
/*
string(64) "var square;
 square = function(x) {
   return x * x;
 };"
*/
```

### Execute CoffeeScript directly in PHP ###

It is also possible to execute your CoffeeScript snippets directly in PHP:

``` php
<?php
var_dump($coffee->execute("
square = (x) -> x * x
square 42
"));
// int(1764)
```


## Dependencies ##

- PHP >= 5.3.0
- [SpiderMonkey PECL](http://pecl.php.net/package/spidermonkey) >= 0.1.4 (beta)


## Links ##

### Project ###
- [Source code](http://github.com/nrk/macchiato/)

### Related ###
- [CoffeeScript](http://coffeescript.org/)
- [SpiderMonkey](http://www.mozilla.org/js/spidermonkey/)
- [PHP](http://php.net/)<commit_msg>Add an example for passing PHP objects and classes to CoffeeScript for execution.<commit_after># Macchiato #

## About ##

__Macchiato__ is a small and __highly experimental__ PHP library, built on top of the
[SpiderMonkey](http://pecl.php.net/package/spidermonkey) PECL extension, that compiles
[CoffeeScript](http://coffeescript.org/) code to JavaScript, or directly executes it.

Unfortunately the SpiderMonkey PECL extension cannot be considered stable at this point.
Compiling CoffeeScript to JavaScript should not pose any problem, but code execution can
lead to random segmentation fault errors.


## A few examples ##

### Create an instance of Macchiato ###

Macchiato requires the CoffeeScript _client_ compiler library in order to work, so you
must pass a valid path or URI for the JavaScript file to the constructor method:

``` php
<?php
$pathToCoffeeScript = 'coffee-script.js';
$coffee = new Macchiato\CoffeeScript($pathToCoffeeScript);
```

### Compile CoffeeScript to JavaScript ###

You can pass your CoffeeScript code to Macchiato and compile it to JavaScript:

``` php
<?php
var_dump($coffee->compile('square = (x) -> x * x'));
/*
string(64) "var square;
 square = function(x) {
   return x * x;
 };"
*/
```

### Execute CoffeeScript directly in PHP ###

It is also possible to execute your CoffeeScript snippets directly in PHP:

``` php
<?php
var_dump($coffee->execute("
square = (x) -> x * x
square 42
"));
// int(1764)
```

### Pass PHP objects and classes to CoffeeScript for execution ###

PHP classes and objects can be made explicitly available to CoffeeScript when executing scripts:

``` php
<?php
$context = $coffee->createContext();
$context->registerVariable('message', ($m = 'Hello there!'));
$context->registerFunction('alert', function($msg) { echo "$msg\n"; });
$coffee->execute('alert(message)', $context);
```


## Dependencies ##

- PHP >= 5.3.0
- [SpiderMonkey PECL](http://pecl.php.net/package/spidermonkey) >= 0.1.4 (beta)


## Links ##

### Project ###
- [Source code](http://github.com/nrk/macchiato/)

### Related ###
- [CoffeeScript](http://coffeescript.org/)
- [SpiderMonkey](http://www.mozilla.org/js/spidermonkey/)
- [PHP](http://php.net/)
{'fraction_non_alphanumeric': 0.14150460593654043, 'fraction_numerical': 0.007164790174002047, 'mean_word_length': 4.657018813314037, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6367417', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1200, 'n_words': 404}