用lua开发iOS应用(Wax)
1.新建一个iOS工程WaxDemo.
2.把原生的.h和.m删除
3.把wax的framework下载下来
wget https://github.com/downloads/probablycorey/wax/wax.framework.zip
4.把wax.framework拉进去工程
5.添加init.lua和ViewController.lua两个文件
6.coding,添加lua初始化代码
- (BOOL)application:(UIApplication
*)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
self.window
= [[UIWindow
alloc]
initWithFrame:[[UIScreen
mainScreen]
bounds]];
self.window.backgroundColor
= [UIColor
whiteColor];
[self.window
makeKeyAndVisible];
wax_start("init.lua",
nil);
return
YES;
}
6.init.lua
require
"ViewController"
viewController =
ViewController:init()
window =
UIApplication:sharedApplication():keyWindow()
window:setRootViewController(viewController)
7.viewController.lua
waxClass{"ViewController",
UIViewController}
function
viewDidLoad(self)
self.super:viewDidLoad(self)
local
label =
UILabel:initWithFrame(CGRect(0,
120,
320, 40))
label:setColor(UIColor:blackColor())
label:setText("Hello
World!")
label:setTextAlignment(UITextAlignmentCenter)
local
font =
UIFont:fontWithName_size("Helvetica-Bold",50)
label:setFont(font)
self:view():addSubview(label)
end
8.运行,then it works!