[Openmcl-devel] Failing to find constant...

Gary Byers gb at clozure.com
Wed Feb 18 21:08:11 UTC 2004



On Wed, 18 Feb 2004, Duncan Rose wrote:

> I'm trying to populate a native NSMutableDictionary object with the
> following:
>
>      (ccl::send dict :set-object font :for-key #$NSFontAttributeName)
>
> but I get the following error on compilation:
>
>  > Error in process listener(1): Constant not found:
> OS::|NSFontAttributeName|
>  > While executing: CCL::LOAD-OS-CONSTANT
>  > Type :GO to continue, :POP to abort.
>  > If continued: Skip loading init file.
>
> Other constants can be found - for example:
>
> (logior #$NSTitledWindowMask #$NSClosableWindowMask
> #$NSMiniaturizableWindowMask #$NSResizableWindowMask)
>
> produces the expected results, so I don't suspect the interface files
> at this time.

NSFontAttributeName isn't a constant; it's a global variable.

Cocoa makes heavier use of global variables than typical C code does;
globals are used so rarely in most vanilla C that it didn't seem worth
providing specialized FFI support for them.  The "unspecialized" FFI
support involves using CCL::FOREIGN-SYMBOL-ADDRESS and %GET-XXX to
do it yourself:

? (ccl::foreign-symbol-address "_NSFontAttributeName") ; note the leading #\_
#<A Mac Pointer #xA3072B34>
? (%get-ptr *)
#<NS-CF-STRING "NSFont" (#xA3087180)>
?

I don't know if these variables are variables simply because their
values are objects, to support internationalization, or for other
reasons.  I've never seen code that tries to change their values,
but I suppose that that one could do so (and probably confuse things
pretty badly by doing so.)

>
> Hoping that the value of NSFontAttributeName is the same as the
> variable name, I also tried:
>
>      (ccl::send dict :set-object font :for-key #@"NSFontAttributeName")
>
> but the font that is drawn is the default for a string with attributes
> (Helvetica 12pt).
>
> The constants are defined in <AppKit/NSAttributedString.h> (relevent
> excerpt below).
>
> /* Predefined character attributes for text. If the key is not in the
> dictionary, then use the default values as described below.
> */
> APPKIT_EXTERN NSString *NSFontAttributeName;             /* NSFont,
> default Helvetica 12 */
> APPKIT_EXTERN NSString *NSParagraphStyleAttributeName;   /*
> NSParagraphStyle, default defaultParagraphStyle */
> APPKIT_EXTERN NSString *NSForegroundColorAttributeName;  /* NSColor,
> default blackColor */
> APPKIT_EXTERN NSString *NSUnderlineStyleAttributeName;   /* int,
> default 0: no underline */
> APPKIT_EXTERN NSString *NSSuperscriptAttributeName;      /* int,
> default 0 */
> APPKIT_EXTERN NSString *NSBackgroundColorAttributeName;  /* NSColor,
> default nil: no background */
>
> Anybody have any ideas how I can access these values?

Somewhere in the Cocoa docs there's a table that shows the default
values of all of these variables.  (NSMutableAttributedString, perhaps ?)

>
> Thanks,

>
> -Duncan
>



More information about the Openmcl-devel mailing list