这篇文档分2个部分,1个是lua绑定教程,(主要来源于引擎目录too/tolua 下的readme文档的翻译),第2个是 3.0 RC0的一些新特性。如果熟知lua绑定的同学,请直接跳过第一部分。
*lua绑定教程
如何使用 bindings-generator
Windows:
- 确保已经安装了
android-ndk-r9b. - 下载python2.7.3(32bit)版本 (http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi).
- 将安装路径例如(C:\Python27)添加到环境变量"Path"中
- 下载并安装pyyaml ( http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.7.exe )
- 下载 pyCheetah( https://raw.github.com/dumganhar/cocos2d-x/download/downloads/Cheetah.zip)解压缩到python的以下路径 “C:\Python27\Lib\site-packages”
- 设置 (
NDK_ROOT)的环境变量 - 在 “cocos2d-x/tools/tolua” 路径下, 用Python运行 “genbindings.py”. 生成好的文件回到 "cocos\scripting\auto-generated\js-bindings"路径之下.
On MAC:
- OSX 10.9系统已经自动集成了python2.7,如果你的系统没有的话,请到官网下载并安装python2.7
- Install python*通过pip安装python依赖文件
sudo easy_install pip
sudo pip install PyYAML
sudo pip install Cheetah
```
* 下载 (http://dl.google.com/android/ndk/android-ndk-r9b-darwin-x86_64.tar.bz2) 你可以在goole的这个地址找到它 (http://developer.android.com/tools/sdk/ndk/index.html)
* 运行
export NDK_ROOT=/path/to/android-ndk-r9b
./genbindings.py
```
On Ubuntu Linux 12.04 64bit
------------
* 安装python:
sudo apt-get install python2.7
*通过pip安装python依赖文件
sudo apt-get install python-pip
sudo pip install PyYAML
sudo pip install Cheetah
```
* 下载 (http://dl.google.com/android/ndk/android-ndk-r9b-darwin-x86_64.tar.bz2) 你可以在goole的这个地址找到它 (http://developer.android.com/tools/sdk/ndk/index.html)
* 在 "cocos2d-x/tools/tolua",路径下 运行
export NDK_ROOT=/path/to/android-ndk-r9b
./genbindings.py
```
**************************************Cocos2d-x 3.0 RC 0 lua 新特性介绍*************************************
1.使用bindings-generator,无需配制pkg文件,只需配制一引起ini文件,具体可参照tools/tolua下的ini配置文件以及README
2.使用module处理不同命名空间的class的绑定,目前有五个module---cc,ccs,ccui,gl和sp
3.使用ScriptHandlerMgr来管理lua 回调函数,这样对于c++ class在回调lua函数时,就无需到c++ class 里面增加如下的代码
virtual void registerScriptTapHandler(int nHandler);
virtual void unregisterScriptTapHandler(void);
```
4.多个功能的lua binding
1)physics ---> TestLua/PhysicsTest
2)spine ---> TestLua/SpineTest
3)XMLHttpRequest ---> TestLua/XMLHttpRequestTest
4)OpenGL ---> TestLua/OpenGLTest
5)New Label ---> TestLua/LabelTestNew
6)New EventDispatcher --->TestLua/NewEventDispatcherTest
7)AssetsManager ---> TestLua/AssetsManagerTest
5.取消了一些类的绑定,直接使用lua table实现,如下:
| CCPoint | lua table
| CCRect | lua table
| CCColor3B | lua table
| CCColor4B | lua table
| CCColor4F | lua table
| CCAffineTransform | lua table
| CCArray | lua table
| CCDictionary | lua table
| CCPointArray | lua table
6,支持lua直接调用objec-c和Java代码(quick中移植)



