Google Groups Home
Help | Sign in
Painlessly add a Nu console to an existing Cocoa application
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Jeff Buck  
View profile
(2 users)  More options Mar 19, 1:55 pm
From: Jeff Buck <wiresanddr...@gmail.com>
Date: Wed, 19 Mar 2008 10:55:43 -0700 (PDT)
Local: Wed, Mar 19 2008 1:55 pm
Subject: Painlessly add a Nu console to an existing Cocoa application
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dean Mao  
View profile
 More options Mar 19, 8:57 pm
From: "Dean Mao" <dean...@gmail.com>
Date: Wed, 19 Mar 2008 17:57:41 -0700
Local: Wed, Mar 19 2008 8:57 pm
Subject: Re: Painlessly add a Nu console to an existing Cocoa application
Nice!  I'm going to have to try this out later tonight!


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google