Skip to content

Commit

Permalink
bundled libffi source from Patrick Geiller and added iOS Xcode project.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Burks committed Jul 2, 2010
1 parent 3cc8cf0 commit 070c8ef
Show file tree
Hide file tree
Showing 31 changed files with 19,315 additions and 2 deletions.
Binary file added iOS/NuApp/Icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
635 changes: 635 additions & 0 deletions iOS/NuApp/NuApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions iOS/NuApp/Resources/Info.plist
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.neontology.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
16 changes: 16 additions & 0 deletions iOS/NuApp/Source/Main/ApplicationDelegate.h
@@ -0,0 +1,16 @@
//
// ApplicationDelegate.h
// NuApp
//
// Created by Tim Burks on 7/2/10.
// Copyright Neon Design Technology, Inc. 2010. All rights reserved.
//

@interface ApplicationDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

26 changes: 26 additions & 0 deletions iOS/NuApp/Source/Main/ApplicationDelegate.m
@@ -0,0 +1,26 @@
//
// ApplicationDelegate.m
// NuApp
//
// Created by Tim Burks on 7/2/10.
// Copyright Neon Design Technology, Inc. 2010. All rights reserved.
//

#import "ApplicationDelegate.h"

@implementation ApplicationDelegate
@synthesize window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
self.window.backgroundColor = [UIColor redColor];
[window makeKeyAndVisible];
return YES;
}

- (void)dealloc {
[window release];
[super dealloc];
}

@end
8 changes: 8 additions & 0 deletions iOS/NuApp/Source/Main/Prefix.pch
@@ -0,0 +1,8 @@
//
// Prefix header for all source files of the 'NuApp' target in the 'NuApp' project
//

#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
33 changes: 33 additions & 0 deletions iOS/NuApp/Source/Main/main.m
@@ -0,0 +1,33 @@
//
// main.m
// NuApp
//
// Created by Tim Burks on 7/2/10.
// Copyright Neon Design Technology, Inc. 2010. All rights reserved.
//

int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSError *error;
NSString *main_nu = [NSString stringWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"main" ofType:@"nu"]
encoding:NSUTF8StringEncoding
error:&error];
NSLog(@"%@", main_nu);
NSLog(@"%d", [main_nu length]);

id parser = [NSClassFromString(@"Nu") parser];

NSLog(@"parsing %@", main_nu);

[parser parseEval:main_nu];
NSLog(@"running");


int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");

NSLog(@"done");

[pool release];
return retVal;
}
Binary file added iOS/NuApp/Support/NuApp.opacity
Binary file not shown.
109 changes: 109 additions & 0 deletions iOS/NuApp/main.nu
@@ -0,0 +1,109 @@
;; test!
;; HelloWorldClassic in Nu
;; a sample iPhone application ported to Nu
;;
;; Copyright 2008, Tim Burks http://blog.neontology.com
;; Released under the Creative Commons Attribution-Share Alike 3.0 license
;; http://creativecommons.org/license/results-one?license_code=by-sa

;; These constants are defined in the UIKit framework headers.
(global UIControlStateNormal 0)
(global UIControlContentHorizontalAlignmentCenter 0)
(global UIControlContentVerticalAlignmentCenter 0)
(global UIControlEventTouchUpInside (<< 1 6))
(global UITextFieldBorderStyleRounded 3)
(global UIKeyboardTypeAlphabet 1)
(global UITextAlignmentCenter 1)
(global UIButtonTypeRoundedRect 1)

(set TEXT_FIELD_FONT_SIZE 15.0)
(set BUTTON_FONT_SIZE 16.0)
(set TEXT_LABEL_FONT_SIZE 30.0)
(set TEXT_FIELD_HEIGHT_MULTIPLIER 2.0)

(class AppDelegate is NSObject
(ivar (id) window (id) contentView (id) textField (id) label)

(- (void)addControlsToContentView:(id)aContentView is
(set contentFrame (aContentView frame))

;; Create a button
(set buttonFrame (list 0.0 0.0 200 40))
(set button (UIButton buttonWithType:UIButtonTypeRoundedRect))
(button setFrame:buttonFrame)
(button setTitle:"Hello" forStates:UIControlStateNormal)
(button setFont:(UIFont boldSystemFontOfSize:BUTTON_FONT_SIZE))

;; Center the text on the button, considering the button's shadow
(button setContentHorizontalAlignment:
UIControlContentHorizontalAlignmentCenter)
(button setContentVerticalAlignment:
UIControlContentVerticalAlignmentCenter)

;; hello: is sent when the button is touched
(button addTarget:self action:"hello:"
forControlEvents:UIControlEventTouchUpInside)

;; Position the button centered horizontally in the contentView
(button setCenter: (list ((aContentView center) first)
(- ((aContentView center) second) 52)))
(aContentView addSubview:button)

;; Create a text field to type into
(set textFieldWidth (* (contentFrame third) 0.72))
;; and set the origin based on centering the view
(set textFieldOriginX (/ (- (contentFrame third) textFieldWidth) 2.0))
(set leftMargin 220.0)
(set textFieldFrame
(list textFieldOriginX leftMargin textFieldWidth
(* TEXT_FIELD_FONT_SIZE TEXT_FIELD_HEIGHT_MULTIPLIER)))
(set aTextField ((UITextField alloc) initWithFrame:textFieldFrame))
(aTextField setBorderStyle: UITextFieldBorderStyleRounded)
(aTextField setFont:(UIFont systemFontOfSize:TEXT_FIELD_FONT_SIZE))
(aTextField setContentVerticalAlignment:
UIControlContentVerticalAlignmentCenter)
(aTextField setPlaceholder:"Touch here and enter your name.")
(aTextField setKeyboardType: UIKeyboardTypeAlphabet)
(set @textField aTextField)

(aContentView addSubview:@textField)

;; Create a label for greeting output.
;; Dimensions are based on the input field sizing
(set leftMargin 90.0)
(set labelFrame
(list textFieldOriginX leftMargin textFieldWidth
(* TEXT_LABEL_FONT_SIZE TEXT_FIELD_HEIGHT_MULTIPLIER)))
(set aLabel ((UILabel alloc) initWithFrame:labelFrame))
(aLabel setFont:(UIFont systemFontOfSize:TEXT_LABEL_FONT_SIZE))
(aLabel setBackgroundColor:(UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.0))
;; Create a slightly muted green color
(aLabel setTextColor:
(UIColor colorWithRed:0.22 green:0.54 blue:0.41 alpha:1.0))
(aLabel setTextAlignment:UITextAlignmentCenter)
((aLabel layer) setMasksToBounds:YES)
((aLabel layer) setCornerRadius:10)
(set @label aLabel)
(aContentView addSubview:@label))

;; This method is invoked when the Hello button is touched
(- (void)hello:(id)sender is
(@textField resignFirstResponder)
(set nameString (@textField text))
(if (eq (nameString length) 0)
(set nameString "Nubie"))
(@label setText:(+ "Hello, " nameString "!")))

(- (void)applicationDidFinishLaunching:(id)application is
;; Set up the window and content view
(set screenRect ((UIScreen mainScreen) bounds))
(set @window ((UIWindow alloc) initWithFrame:screenRect))

(set @contentView ((UIView alloc) initWithFrame:screenRect))
(@contentView setBackgroundColor:(UIColor scrollViewTexturedBackgroundColor))

(@window addSubview:@contentView)
(self addControlsToContentView:@contentView)

;; Show the window
(@window makeKeyAndVisible)))
21 changes: 21 additions & 0 deletions iOS/libffi/LICENSE
@@ -0,0 +1,21 @@
libffi - Copyright (c) 1996-2008 Red Hat, Inc and others.
See source files for details.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
``Software''), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 changes: 28 additions & 0 deletions iOS/libffi/README.markdown
@@ -0,0 +1,28 @@
libffi for the iPhone
=

**[libffi](http://sourceware.org/libffi/)** allows calling any C-function or ObjC method at runtime.

**libffi-iphone** is a stripped down version of libffi, tailored just for the iPhone. **libffi-iphone** includes source code for both the iPhone simulator and the iPhone itself.

Calling functions
-
Works just like libffi.

Creating ffi closures, new functions created and called at runtime
-
ffi closures don't work on the iPhone, as <code>mprotect</code> is disabled.

You can however retarget existing functions if you have a function pool. See [Tim Burks' post about Nu's method pool](http://stackoverflow.com/questions/219653/ruby-on-iphone), see [JSCocoa's Burks Pool](http://github.com/parmanoir/jscocoa/blob/master/JSCocoa/iPhone/BurksPool.m) for another implementation.

To retarget an ObjC pool method, use the method's hidden <code>_cmd</code> argument (the current selector) and <code>[self class]</code>. This will tell you which method of which class is being called.

License
-
**libffi-iphone** uses **libffi**'s license.

Hey
-
Problems, questions <br/>
Patrick Geiller <br/>
[parmanoir@gmail.com](mailto:parmanoir@gmail.com)

0 comments on commit 070c8ef

Please sign in to comment.