Skip to content

Commit

Permalink
Updated Twitter example.
Browse files Browse the repository at this point in the history
  • Loading branch information
probablycorey committed Jan 3, 2011
1 parent adf5a3d commit 672e89b
Show file tree
Hide file tree
Showing 73 changed files with 2,588 additions and 2,085 deletions.
2 changes: 1 addition & 1 deletion examples/TwitterApp/Classes/ProtocolLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// This seems to be a bug, or there is a runtime method I'm unaware of

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface ProtocolLoader : NSObject <UIApplicationDelegate, UIWebViewDelegate, UIActionSheetDelegate, UIAlertViewDelegate, UISearchBarDelegate, UITextViewDelegate, UITabBarControllerDelegate> {}
@end
Expand Down
71 changes: 0 additions & 71 deletions examples/TwitterApp/Classes/WaxTextField.h

This file was deleted.

838 changes: 425 additions & 413 deletions examples/TwitterApp/TwitterApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions examples/TwitterApp/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
// main.m
// TwitterApp
//
// Created by Corey Johnson on 3/7/10.
// Copyright __MyCompanyName__ 2010. All rights reserved.
// Created by Corey on 1/3/11.
// Copyright me 2011. All rights reserved.
//
// This where the magic happens!
// Wax doesn't use nibs to load the main view, everything is done within the
// AppDelegate.lua file

#import <UIKit/UIKit.h>

#import "ProtocolLoader.h"
#import "WaxTextField.h"

#import "wax.h"
#import "wax_http.h"
#import "wax_json.h"
Expand All @@ -22,7 +19,7 @@
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

wax_startWithExtensions(luaopen_wax_http, luaopen_wax_json, luaopen_wax_xml, nil);
wax_start("AppDelegate.lua", luaopen_wax_http, luaopen_wax_json, luaopen_wax_xml, nil);

int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");
[pool release];
Expand Down
File renamed without changes.
63 changes: 31 additions & 32 deletions examples/TwitterApp/wax/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Wax is a framework that lets you write iPhone apps in [Lua](http://www.lua.org/a
Setup
-----

1. Download wax [http://github.com/probablycorey/wax/downloads](http://github.com/probablycorey/wax/downloads)
1. Clone wax [http://github.com/probablycorey/wax/](http://github.com/probablycorey/wax/)

2. From the command line, **cd** into wax folder and type **rake install**. This will install an xcode project template.
2. From the command line, **cd** into wax folder created above and type **rake install**. This will install an xcode project template.

3. Open up xcode and create a new **Wax** project, it should be located under the **User Tempates** section.
3. Open up xcode and create a new **Wax** project, it should be located under the **User Tempates** section.

4. Build and Run! You've got lua running on the iPhone!

Expand Down Expand Up @@ -39,11 +39,13 @@ You get all of this with Lua, with no downside!
Examples
--------

For some simple Wax apps, check out the [examples folder](http://github.com/probablycorey/wax/tree/master/examples/).

How would I create a UIView and color it red?

-- forget about using alloc! Memory is automatically managed by Wax
view = UIView:initWithFrame(CGRect(0, 0, 320, 100))

-- use a colon when sending a message to an Objective-C Object
-- all methods available to a UIView object can be accessed this way
view:setBackgroundColor(UIColor:redColor())
Expand All @@ -67,7 +69,7 @@ What if I want to create a custom UIViewController?
-- Created in "MyController.lua"
--
-- Creates an Objective-C class called MyController with UIViewController
-- as the parent. This is a real Objective-C object, you could even
-- as the parent. This is a real Objective-C object, you could even
-- reference it from Objective-C code if you wanted to.
waxClass{"MyController", UIViewController}

Expand All @@ -80,22 +82,38 @@ What if I want to create a custom UIViewController?
function viewDidLoad()
-- Do all your other stuff here
end

You said HTTP calls were easy, I don't believe you...

url = "http://search.twitter.com/trends/current.json"
-- Makes an asyncronous call, the callback function is called when a

-- Makes an asyncronous call, the callback function is called when a
-- response is received
wax.http.request{url, callback = function(body, response)
-- request is just a NSHTTPURLResponse
puts(response:statusCode())

-- Since the content-type is json, Wax automatically parses it and places
-- it into a Lua table
puts(body)
puts(body)
end}


Since Wax converts NSString, NSArray, NSDictionary and NSNumber to native Lua values, you have to force objects back to Objective-C sometimes. Here is an example.

local testString = "Hello lua!"
local bigFont = UIFont:boldSystemFontOfSize(30)
local size = toobjc(testString):sizeWithFont(bigFont)
puts(size)

Tutorials
---------

[Setting up iPhone wax](http://probablyinteractive.com/2009/10/18/Setting-up-iPhone-Wax.html)

[How does iPhone Wax work?](http://probablyinteractive.com/2009/10/19/How-does-iPhone-Wax-work.html)

[Twitter client in Wax](http://probablyinteractive.com/2009/10/20/Wax-talks-to-twitter.html)

Which API's are included?
-------------------------

Expand Down Expand Up @@ -126,23 +144,4 @@ Fork it, change it, commit it, push it, send pull request; instant glory!

The MIT License
---------------
Copyright (c) 2008
Rob Ellis, Brock Whitten, Brian Leroux, Joe Bowser, Dave Johnson, Nitobi

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.
Wax is Copyright (C) 2009 Corey Johnson See the file LICENSE for information of licensing and distribution.
13 changes: 13 additions & 0 deletions examples/TwitterApp/wax/TIPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- Download the Lua source from http://www.lua.org/download.html

- Patch LUA_SOURCE/src/Makefile to make it 32-bit
# Change this line
macosx:
- $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"
+ $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX -arch i386" MYLIBS="-arch i386 -lreadline"

- Make Lua:
make macosx

- Cross-compile the lua files!
/usr/bin/arch -arch i386
40 changes: 27 additions & 13 deletions examples/TwitterApp/wax/bin/hammer
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ class Hammer
@args = {"-configuration" => "Debug"}
@settings = {}

@should_run_tests = false
@should_run_headless = false
@should_run = false
@verbose = false
@device = "iphone"

def self.setup
opts = OptionParser.new do |opts|
Expand All @@ -39,15 +40,19 @@ class Hammer
@settings["PRODUCT_NAME"] = v
end

opts.on("-t", "--test", "Run all tests") do
@should_run_tests = true
opts.on("-h", "--headless", "Just runs the app from the command line, no simulator") do
@should_run_headless = true
end

opts.on("-r", "--run", "Run the app in the simulator") do
@should_run = true

end

opts.on("-d", "--device ARG", "Choose what device to run on (iphone/ipad)") do |v|
@device = v
end

opts.on("-s", "--sdk ARG", "Choose he SDK. Use --showsdks to see options.") do |v|
v = "iphonesimulator#{v}" if v =~ /^[\d\.]+/ # if only the version is given... assume user wants a simulator build
@args["-sdk"] = v
Expand All @@ -71,12 +76,18 @@ class Hammer
if !@args["-sdk"]
output = `xcodebuild -showsdks`
sdks = output.scan(/-sdk (.*?$)/m).map {|a| a.join}
@args["-sdk"] = sdks.find_all {|sdk| sdk =~ /iphonesimulator/}.sort.first

if @device !~ /pad/i # remove sdk version 3.2, it is ipad only
sdks.reject! {|a| a =~ /3.2$/}
end

@args["-sdk"] = sdks.find_all {|sdk| sdk =~ /iphonesimulator/}.sort.last
end
end

def self.build # Build the app
extra_args = ARGV

extra_args += ["build"] if extra_args.empty?
arg_string = @args.collect {|k, v| v ? "#{k} #{v}" : k}.join(" ")
setting_string = @settings.collect {|k, v| v ? "#{k}=#{v}" : k}.join(" ")
Expand All @@ -88,8 +99,10 @@ class Hammer

if @verbose or not successful
puts output
puts("** BUILD FAILED **") if not successful
exit 1
if not successful
puts("** BUILD FAILED **")
exit 1
end
end

# Take on the builds ENV
Expand All @@ -98,8 +111,8 @@ class Hammer
return output
end

def self.test
return if not @should_run_tests
def self.headless
return if not @should_run_headless
if ENV["PLATFORM_NAME"] !~ /simulator/
puts "Can only run tests on the simulator not #{ENV["PLATFORM_NAME"]}"
exit 1
Expand All @@ -115,9 +128,7 @@ class Hammer

FileUtils.rm_rf(ENV["CFFIXED_USER_HOME"]) if File.exists?(ENV["CFFIXED_USER_HOME"])
FileUtils.mkdir_p(ENV["CFFIXED_USER_HOME"] + "/Documents")

ENV["WAX_TEST"] = "YES"


system("#{self.app_path}/#{ENV['EXECUTABLE_NAME']} -RegisterForSystemEvents")

exit 0
Expand All @@ -126,7 +137,10 @@ class Hammer
def self.run
return if not @should_run
`/usr/bin/killall "iPhone Simulator" 2> /dev/null` #make sure the simulator is killed
system "wax/bin/waxsim #{self.app_path} #{File.expand_path('.')}"
sdk_version = @args["-sdk"][/([\d\.]+)/, 1]
cmd = "wax/bin/waxsim -d #{@device} -s #{sdk_version} #{self.app_path} #{File.expand_path('.')}"
puts cmd
system cmd
end

def self.app_path
Expand All @@ -138,6 +152,6 @@ Hammer.setup

Hammer.build

Hammer.test
Hammer.headless

Hammer.run
Loading

0 comments on commit 672e89b

Please sign in to comment.