Framework
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 frameworkafter 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 FrameworkThe 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 install_name_tool -change @executable_path/../Frameworks/Pike.framework/Pike @loader_path/../Frameworks/Pike.framework/Pike path/to/bundle/executablegcc -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("%sn", 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: %dn", sv->type, sv->u.integer); free_svalue(sv); // finally, we clean up. [i stopInterpreter]; [innerPool release]; return 0; } Powered by PikeWiki2 |
|||
gotpike.org | Copyright © 2004 - 2009 | Pike is a trademark of Department of Computer and Information Science, Linköping University |