<p>Here are some of the ways that you can use Nu.</p>
</div>
<divclass="extended">
<h2>Scripting and interacting with nush, the Nu shell</h2>
<p>A simple way to use Nu is to write programs that run in nush, the Nu shell.</p>
<p><strong>nush command-line options</strong></p>
<tablestyle="background:#eee">
<tr>
<tdwidth="40%">
-f <em>framework</em>
</td>
<td>
Loads the named framework. This option may be specified multiple times.
</td>
</tr>
<tr>
<td>
-e <em>expression</em>
</td>
<td>
Evaluates the specified Nu expression.
This option may be specified multiple times.
</td>
</tr>
<tr>
<td>
-i
</td>
<td>
Runs the interpreter interactively at the console.
This need not be specified if no filename is given
as an argument.
</td>
</tr>
<tr>
<td>
<em>filename</em>
</td>
<td>
Loads and evaluates the named file.
</td>
</tr>
</table>
<p>Running nush interactively is a great way to explore and test
Objective-C components.</p>
<p>You can write executable scripts in Nu if you begin them with a
"shebang" line that identifies nush as the shell. For example,</p>
<pre>
#!/usr/bin/env nush
(puts "Everything old is Nu again.")
</pre>
<h2>Building Cocoa Applications</h2>
<p>Another way to use Nu is to use it to write Cocoa applications.</p>
<h3>Option 1: No compilation needed</h3>
<p>If you don't need to compile any Objective-C code into your application
then you can build a Cocoa application by simply copying nush into the
<code>Contents/MacOS</code> directory of your application bundle and renaming it to your application's name. Upon startup, the resulting application will load and evaluate a file named <strong>main.nu</strong>
from its <code>Contents/Resource</code> directory. <br/>
To see examples of this, see the <ahref="/randomapp">RandomApp</a>,
<p>If you have Objective-C code to compile into your application, you could
compile it into a framework and load it from Nu, making it unnecessary to ever use anything but nush as the main program of your application.</p>
<h3>Option 2: Compile and use the Nu main function</h3>
<p>If you want to compile your Objective-C code directly into your application, you can make your application start with Nu by having it use the following <code>main()</code> function:</p>
<pre>
extern int NuMain(int argc, const char *argv[]);
int main(int argc, const char *argv[])
{
return NuMain(argc, argv);
}
</pre>
<p>This also will look for a <strong>main.nu</strong> file in your application's <code>Contents/Resource</code> directory upon
startup. <br/>
See the <ahref="/benwanu">Benwanu</a> sample program for an example that compiles Objective-C code and the <strong>NuMain()</strong> function directly into an application.</p>
<h3>Option 3: Load and use the Nu parser at runtime</h3>
<p>If you don't want to modify your <code>main()</code> function, you can also use Nu
by loading the Nu framework into your application and using the Nu
class to get a parser.</p>
<pre>
id parser = [Nu parser];
</pre>
<p>You can then use this parser to parse and evaluate Nu expressions,
which you can load from a file or provide inline.</p>
<pre>
id code = [parser parse:@"(+ 2 2)"];
id result = [parser eval:code];
</pre>
<p>In this case, the result of the evaluation will be an NSNumber with
an integer value of 4.</p>
<h2>Building Cocoa Frameworks</h2>
<p>A third way to use Nu is to use it in a Cocoa framework that you write.
There are nuke tasks to help you with this; they require that you compile
at least a small amount of C code for your framework, but in practice,
interesting frameworks will probably be a combination of Nu and Objective-C.</p>
<p>One important C function that your framework should include is an initialization
function. This function will load the equivalent of "main.nu" for your