On Wed, Mar 19, 2008 at 10:55 AM, Jeff Buck <wiresanddr
...@gmail.com> wrote:
> I wanted to see how painlessly I could add a permanent Nu console to
> an existing Cocoa application (in code, without manually using
> NuAnywhere). It turned out to be really easy. All of the needed
> pieces of code were on the Nu website or in the example Nu
> applications. I just whittled them down to a few lines in a single .m
> file.
> First, add Nu.framework to your project.
> There are a few places you could add the Nu console startup code in
> your Cocoa application. I put the code at the end of the awakeFromNib
> method of my main controller class:
> // At top of .m file:
> #import "Nu/Nu.h"
> // ...
> - (void)awakeFromNib
> {
> // ...
> NSString* consoleStartup =
> @"(progn \
> (load \"console\") \
> (set $console ((NuConsoleWindowController alloc) init)))";
> id parser = [Nu parser];
> id code = [parser parse:consoleStartup];
> id result = [parser eval:code];
> }
> Compile and run your application. Command-L will bring up the Nu
> console. If you want the Nu console to automatically appear on
> application startup, add
> ($console toggleConsole:nil)
> as the last line of the progn in the consoleStartup string above.
> Now, start exploring:
> > (((NSApplication sharedApplication) mainWindow) firstResponder)
> <LifeView:478240>
> > (set lv (((NSApplication sharedApplication) mainWindow) firstResponder))
> <LifeView:478240>
> > (set lc (lv lifeController))
> <LifeController:453010>
> > ((lc instanceMethods) each: (do (method) (puts (method name))))
> awakeFromNib
> changeSpeed:
> clear:
> gridChangeRows:columns:
> gridChangeWrap:
> init
> life
> loadGliderGun:
> loadPattern:
> randomize:
> showPreferences:
> singleGeneration:
> start:
> stop:
> timerUp:
> toggleCellAtX:y:
> toggleRunning:
> view
> windowShouldClose:
> <NSCFArray:14831090>
> I used F-Script a lot in the past, but I can't say that I ever warmed
> up it's syntax. Nu in a console feels like home.
> -Jeff