iPhone Wax is is a Lua framework to make iPhone app development faster! What is the advantage of writing apps in Lua? Lua is a modern dynamic language, like Ruby or Python. Because of that you can be more expressive in less lines of code, take advantage of modern language techniques and extend Lua any way you see fit!
Go to http://github.com/probablycorey/wax and do what the README says.
Don't know Lua? If you are familiar with Javascript, Python, Ruby or any dynamic language you can learn the basics of Lua in 15 minutes! You can check out these free tutorials or buy a copy of Programing in Lua.
Open up Xcode and create a new project using the Wax template (The wax template is installed by following these instructions). You can name the project whatever you want, I'm going to be super generic and call mine TableView.
From now on APP_ROOT references the path of this Xcode project.
Run the app! You'll get a simple "Hello Lua" program running in your iPhone Simulator!
You don't need to edit the Lua code from Xcode, it's all located in the APP_ROOT/date/scripts directory, so open up your favorite text editor and go at it! You should also look at Wax's support files at APP_ROOT/wax/lib/wax-scripts.
To create the TableView, first create a new file called APP_ROOT/data/scripts/MyTableViewController.lua
Create a new obj-c controller class with this call
waxClass{"MyTableViewController", UITableViewController}
Now add the init function, it will setup the tableView's contents and call the super's init (just like in obj-c!)
function init(self) self.super:initWithStyle(UITableViewStylePlain) -- Here are the tableView's contents self.things = {"Planes", "Trains", "Automobiles"} return self end
Now we need to implement methods from the UIDataSource protocol. The final MyTableViewController.lua file should look like this.
waxClass{"MyTableViewController", UITableViewController}
function init(self)
self.super:initWithStyle(UITableViewStylePlain)
-- Here are the tableView's contents
self.things = {"Planes", "Trains", "Automobiles"}
return self
end
function numberOfSectionsInTableView(self, tableView)
return 1
end
function tableView_numberOfRowsInSection(self, tableView, section)
return #self.things
end
function tableView_cellForRowAtIndexPath(self, tableView, indexPath)
local identifier = "MyTableViewControllerCell"
local cell = tableView:dequeueReusableCellWithIdentifier(identifier) or
UITableViewCell:initWithStyle_reuseIdentifier(UITableViewCellStyleDefault, identifier)
local thing = self.things[indexPath:row() + 1] -- Must +1 because Lua arrays are 1 based
cell:textLabel():setText(thing)
return cell
end
All that is left is to create an instance of MyTableViewController and add it to the main window. We do this by editing APP_ROOT/data/scripts/AppDelegate.lua. This is the same as the UIApplicationDelegate you use in an Objective-C app.
require "MyTableViewController" waxClass{"AppDelegate", protocols = {"UIApplicationDelegate"}} function applicationDidFinishLaunching(self, application) local frame = UIScreen:mainScreen():bounds() self.window = UIWindow:initWithFrame(frame) self.controller = MyTableViewController:init() self.window:addSubview(self.controller:view()) self.window:makeKeyAndVisible() end
Run the app... You will have a really simple/boring UITableView that was created via Lua!
That's just the beginning of what you can do with iPhone Wax!
Recent Posts