digitalmars.D - Hello Carbon World (Mac)
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (10/61) Dec 09 2004 Speaking of GUIs...
- John Reimer (4/76) Dec 09 2004 Looks fun!
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (4/9) Dec 09 2004 Common and common... It is just what the sample code used ?
Speaking of GUIs... For reference, here is what Hello World looks like for the Carbon API of Mac OS X, ported over to D:import std.stdio; typedef void* CFStringRef; typedef void* IBNibRef; typedef void* WindowRef; alias int OSStatus; const OSStatus noErr = 0; CFStringRef CFSTR(char[] str) { return __CFStringMakeConstantString(cast(char *) str); } int main(char[][] args) { IBNibRef nibRef; WindowRef window; OSStatus err; // Create a Nib reference passing the name of the nib file (without the .nib extension) // CreateNibReference only searches into the application bundle. err = CreateNibReference(CFSTR("main"), &nibRef); if (err != noErr) goto CantGetNibRef; // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar // object. This name is set in InterfaceBuilder when the nib is created. err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar")); if (err != noErr) goto CantSetMenuBar; // Then create a window. "MainWindow" is the name of the window object. This name is set in // InterfaceBuilder when the nib is created. err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window); if (err != noErr) goto CantCreateWindow; // We don't need the nib reference anymore. DisposeNibReference(nibRef); // The window was created hidden so show it. ShowWindow(window); // Call the event loop RunApplicationEventLoop(); writefln("Goodbye from D"); CantCreateWindow: CantSetMenuBar: CantGetNibRef: return err; }Compiles and runs just fine, with the proper extern(C) {} definitions and a GCC/GDC patched with framework support:gdc -o build/HelloWorld.app/Contents/MacOS/HelloWorld main.d -framework CarbonOf course, real application use more than those 6 functions above :-) And adding a "Hello, World!" in InterfaceBuilder is probably cheating. --anders PS. The rest of the app was just "New Project > Carbon Application" (C) Xcode support for the GDC compiler is not yet fully completed...
Dec 09 2004
Anders F Björklund wrote:Speaking of GUIs... For reference, here is what Hello World looks like for the Carbon API of Mac OS X, ported over to D:Looks fun! Is it common practice in Carbon programming to use all those gotos. That seems strange.import std.stdio; typedef void* CFStringRef; typedef void* IBNibRef; typedef void* WindowRef; alias int OSStatus; const OSStatus noErr = 0; CFStringRef CFSTR(char[] str) { return __CFStringMakeConstantString(cast(char *) str); } int main(char[][] args) { IBNibRef nibRef; WindowRef window; OSStatus err; // Create a Nib reference passing the name of the nib file (without the .nib extension) // CreateNibReference only searches into the application bundle. err = CreateNibReference(CFSTR("main"), &nibRef); if (err != noErr) goto CantGetNibRef; // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar // object. This name is set in InterfaceBuilder when the nib is created. err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar")); if (err != noErr) goto CantSetMenuBar; // Then create a window. "MainWindow" is the name of the window object. This name is set in // InterfaceBuilder when the nib is created. err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window); if (err != noErr) goto CantCreateWindow; // We don't need the nib reference anymore. DisposeNibReference(nibRef); // The window was created hidden so show it. ShowWindow(window); // Call the event loop RunApplicationEventLoop(); writefln("Goodbye from D"); CantCreateWindow: CantSetMenuBar: CantGetNibRef: return err; }Compiles and runs just fine, with the proper extern(C) {} definitions and a GCC/GDC patched with framework support:gdc -o build/HelloWorld.app/Contents/MacOS/HelloWorld main.d -framework CarbonOf course, real application use more than those 6 functions above :-) And adding a "Hello, World!" in InterfaceBuilder is probably cheating. --anders PS. The rest of the app was just "New Project > Carbon Application" (C) Xcode support for the GDC compiler is not yet fully completed...
Dec 09 2004
John Reimer wrote:Common and common... It is just what the sample code used ? It avoids nesting if's, but try/catch is somewhat neater :-) --andersFor reference, here is what Hello World looks like for the Carbon API of Mac OS X, ported over to D:Is it common practice in Carbon programming to use all those gotos. That seems strange.
Dec 09 2004