標籤:lua ios wax
用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= [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];
self.window.backgroundColor= [UIColorwhiteColor];
[self.windowmakeKeyAndVisible];
wax_start("init.lua",nil);
return YES;}
6.init.lua
require"ViewController"viewController =ViewController:init()window =UIApplication:sharedApplication():keyWindow()window:setRootViewController(viewController)
7.viewController.luawaxClass{"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!
用lua開發iOS應用(Wax)