Wax介绍
创建LuaWax工程
cocos new -l lua -p com.example.luawax LuaWax --portrait
添加头文件路径
${SDKROOT}/usr/include/libxml2
添加依赖库
libsqlite3.tbd
libxml2.tbd
下载wax4cocos
git clone https://git.coding.net/richie/wax4cocos.git
添加wax4cocos到工程
复制wax4cocos/lua/wax到src/wax
在proj.ios_mac下新建libs目录
复制wax4cocos/native/wax到libs/wax
复制support/gamekit 到 Classes/../gamekit下
使用xcode添加libs/wax和gamekit到工程中
修改工程文件
@AppDelegate.cpp
cocos_wax_initialize()
cocos_wax_start("main.lua");
@app/views/MainScene.lua
-- show a alert and print click callback
-- create Class MyLuaAlertDelegate that support UIAlertViewDelegate
waxClass{"MyLuaAlertDelegate",NSObject,protocols = {"UIAlertViewDelegate"}}
function MyLuaAlertDelegate:alertView_clickedButtonAtIndex(alert,index)
print("alertView_clickedButtonAtIndex = "..tostring(index))
end
-- create a instance of MyLuaAlertDelegate
-- we need store it to self.callback,
-- if not, instance will remove by wax gc
self.callback = MyLuaAlertDelegate:init()
-- create a uialertview and set delegate
print("show alert ".. tostring(self.count))
local title = "Title"
local message = "Message"
local alert = UIAlertView:init()
alert:setTitle(title)
alert:setMessage(message)
alert:addButtonWithTitle("OK")
alert:addButtonWithTitle("Cancel")
alert:setDelegate(self.callback)
alert:show()
网友评论