[Openmcl-devel] interactive nib loading
R. Matthew Emerson
rme at clozure.com
Wed Jan 30 17:55:00 PST 2008
On Jan 30, 2008, at 7:15 PM, Osei Poku wrote:
> I could not even get past the first step. This was the error
>
> ? (make-instance 'ns:ns-nib :with-nib-named #@"/Users/opoku/Work/
> myUI.nib" :bundle +null-ptr+)
> > Error: No applicable method for args:
> > (#<A Null Foreign Pointer> :WITH-NIB-NAMED #<NS-CONSTANT-
> STRING "/Users/opoku/Work/myUI.nib" (#x192057C0)> :BUNDLE #<A Null
> Foreign Pointer>)
> > to #<STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE
> #x3000401B935F>
> > While executing: #<CCL::STANDARD-KERNEL-METHOD NO-APPLICABLE-
> METHOD (T)>, in process Listener(76).
> > Type :POP to abort, :R for a list of available restarts.
> > Type :? for other options.
I cited the wrong method for getting nib files from anywhere. Sorry
about that.
If you're completely new to Cocoa, you're in for a bit of studying.
You might pick up a copy of Hillegass (see link to it on http://trac.clozure.com/openmcl/wiki/CocoaBridge)
and work through if you haven't already.
Objective-C translates in a fairly obvious way to lisp code,
especially if you don't use the CLOS-y way of creating Obj-C instances.
Back to the nib case---the right method is probably NSNib's #/
initWithContentsOfURL:.
(let* ((url (#/fileURLWithPath: ns:ns-url #@"/my/path/name"))
(nib (#/initWithContentsOfURL: (#/alloc ns:ns-nib) url))
(top-level-objs +null-ptr+))
(rlet ((p :address top-level-objs))
(#/instantiateNibWithOwner:topLevelObjects: nib *nsapp* p))
;; do something with the results
(#/release nib))
You might need to do more fiddling, of course. You'll presumably want
the nib's owner (which I made *nsapp*) to be an instance of some
custom controller class that you define, and you'll have to take care
of releasing the nib's top-level objects when you're done with them.
You can also create Cocoa objects completely programmatically; in
some cases this can be simpler than using a nib file (which generally
assumes that it's going to be loaded from a bundle).
By the way, there's nothing second-class about creating objects
programmatically versus using a nib: they all call the exact same
code in the end. There's nothing magical about nib-archived objects.
>
>
>
> On Jan 30, 2008, at 5:49 PM, R. Matthew Emerson wrote:
>
>>
>> On Jan 30, 2008, at 3:27 PM, Osei Poku wrote:
>>
>>> This question is likely due to my lack of familiarity with Cocoa/
>>> Objective C API and/or the corresponding openmcl bridge. But I have
>>> attempted to find help in the documentation to no avail.
>>>
>>> Essentially, I want to create an interface using Interface Builder
>>> save it and then load it interactively at the openmcl repl. I
>>> simply
>>> do not even know which Cocoa function to use to load the nib file.
>>> This is complicated by the fact that the nib file is in the wild
>>> (some
>>> arbitrary path). I am going to go back and read some more about the
>>> interface builder but I would appreciate some help on the
>>> programmatic
>>> end.
>>>
>>> The closest matches to what I want seem to be by using the NSNib or
>>> NSBundle classes to load the nib file however, I am confused as to
>>> what arguments to give the various instantiate function on the lisp
>>> side.
>>
>> You'll probably want to use NSNib for this, since you say that your
>> nib file will be at an arbitrary location.
>>
>> See:
>>
>> http://developer.apple.com/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/chapter_3_section_6.html
>>
>> Something like (untested, probably wrong, etc.)
>>
>> (let* ((nib (make-instance 'ns:ns-nib :with-nib-named #@"path/to/nib"
>> :bundle +null-ptr+))
>> (top-level-objs +null-ptr+))
>> (rlet ((p :address top-level-objs))
>> (#/instantiateNibWithOwner:topLevelObjects: nib owner p))
>> (#/release nib)
>> ;; etc., see example in docs cited above about releasing top level
>> objects
>> ...)
>>
>> Note that the nib file path needs to be an NSString, not a lisp
>> string.
>>
>>
>>
>
More information about the Openmcl-devel
mailing list