Framework

[ Start > PikeDevel > Framework ] [ Edit this Page | Show Page Versions | Show Raw Source ]


Pike 7.7 has support for building an Objective-C framework for use with Darwin. This framework allows Pike to be embedded in any Objective-C application.

Creating the framework

after successfully building pike from 7.7 CVS, enter the build directory (build/platform_name) and run "make framework".

successful completion of this should leave Pike.framework in the current directory.

the framework is designed to be located within a "Cocoa" application's Frameworks directory (@executable_dir/../Frameworks), so if you want to install the framework within a standard location, like /Library/Frameworks, you'll need to use the install_name_tool utility to change that location.

A small sample program is included in comments at the end of src/OCPikeInterpreter.m.

Building a Universal Framework

The framework built by "make framework" places any platform specific modules in the Resources/platform directory, and the master is able to accomodate this. Therefore, the only file that needs to be made Universal is Pike.framework/Versions/Current/Pike. Use the "lipo" tool to make a fat binary of this file from versions of the file compiled for the desired platforms (currently, this should be Power_Macintosh and i386).

Assuming you have made frameworks for both platforms, the following commands should yield a Universal framework in the build/Frameworks directory:

cd build
mkdir Frameworks
cp -rf darwin-8.9.1-i386/Pike.framework Frameworks
cp -rf darwin-8.9.1-power-macintosh/Pike.framework/Versions/Current/Resources/Power_Macintosh Frameworks/Pike.framework/Versions/Current/Resources
lipo darwin-8.9.1-i386/Pike.framework/Versions/Current/Pike darwin-8.9.1-power-macintosh/Pike.framework/Versions/Current/Resources/Pike -output Frameworks/Pike.framework/Versions/Current/Pike

Using the framework

Once a pike framework has been built, using it is similar to using any other framework. Because the framework is built with the anticipation it will be used in an embedded form, make sure that you've installed Pike.framework in ../Frameworks from where you run this code. As noted above, install_name_tool can be used to make this a different location, such as /Library/Frameworks.

If using the framework embedded within a loadable bundle (such as a preference pane or screensaver), you should use install_name_tool to change the load location to begin with @loader_path (magic identifier indicating the path to the bundle requesting the load) instead of @executable_path (magic identifier indicating the path of the current executable).

install_name_tool -change @executable_path/../Frameworks/Pike.framework/Pike @loader_path/../Frameworks/Pike.framework/Pike path/to/bundle/executable

gcc -arch ppc -FTestBundle.saver/Contents/Frameworks -c BWTestBundle.m -o BWTestBundle.o MACOSX_DEPLOYMENT_TARGET="10.4" gcc -arch ppc BWTestBundle.o -bundle -o TestBundle -FTestBundle.saver/Contents/Frameworks -framework Pike -framework Foundation -undefined dynamic_lookup -framework ScreenSaver

gcc -F../Frameworks -c test.m -o test.o
gcc test.o -o test -F../Frameworks -framework Pike  -framework Foundation
./test

#import <Pike/OCPikeInterpreter.h>
#import <Foundation/NSString.h>
#import <Foundation/NSAutoreleasePool.h>

int main() { id i; struct svalue * sv;

// required for console mode objective c applications NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];

// these 2 lines set up and start the interpreter. i = [OCPikeInterpreter sharedInterpreter]; [i startInterpreter];

// ok, now that we have things set up, let's use it. // first, an example of calling pike c level apis directly. f_version(0); printf("%s&#110;", Pike_sp[-1].u.string->str); pop_stack();

// next, we'll demonstrate one of the convenience functions available sv = [i evalString: @"1+2"]; printf("type: %d, value: %d&#110;", sv->type, sv->u.integer); free_svalue(sv);

// finally, we clean up. [i stopInterpreter]; [innerPool release]; return 0; }

See Also

-Building a Cocoa App


Powered by PikeWiki2

 
gotpike.org | Copyright © 2004 - 2009 | Pike is a trademark of Department of Computer and Information Science, Linköping University