网上有好多写如何讲自己定义的方法绑定到lua的文章,当中都仅仅对环境配置做了简单的介绍,看到有的帖子写在绑定中遇到了各种各样的error。大部分是因为环境配置不对导致的,下面是官方的文档有标准的说明,里面说明了使用bindings-generator的环境须要,详细的如何配置路径网上多事一堆一堆的我把python用到的pyyaml和pyCheetah须要放置的路径写在了下面,全部的开发引擎都会有自己的说明文档。下面就是cocos2dx 官方文档 //如何使用 bindings-generator How to Use bindings-generator ================== //windows 环境下 On Windows: ------------ //安装android-ndk-r9b * Make sure that you have installed `android-ndk-r9b`. //下载 python2.7.3 * Download python2.7.3 (32bit) from (http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi). //把python安装路径配置到path(windows 环境变量配置) * Add the installed path of python (e.g. C:Python27) to windows environment variable named 'PATH'. //下载pyyaml而且安装 * Download pyyaml from http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.7.exe and install it. //下载 pyCheetah 而且解压到安装python路径的Lib目录下的site-packages目录下 * Download pyCheetah from https://raw.github.com/dumganhar/my_old_cocos2d-x_backup/download/downloads/Cheetah.zip, unzip it to "C:Python27Libsite-packages" 设置ndk——root合法的环境变量 * Set environment variables (`NDK_ROOT`) * Go to "cocos2d-x/tools/tolua" folder, and run "genbindings.py". The generated codes will be under "cocosscriptingauto-generatedjs-bindings". //mac环境下 On MAC: ---------- //,mac 10.9的系统版本号已经默认安装好了python2.7。假设你的mac 没有安装好则使用pip工具安装 * The OSX 10.9 has a built-in python2.7 and if your os don't have python2.7 then use [Homebrew](http://brew.sh/) to install the python and use pip install the python dependencies. <pre> brew install python </pre> //安装python须要用到的库 通过一下命令 * Install python dependices by pip. <pre> //在命令行输入下面命令进行安装 sudo easy_install pip //安装pip sudo pip install PyYAML //安装 pyYAMl 成功时回有个successfully提示 sudo pip install Cheetah //安装 Cheetah 成功时也会提示successfully提示 </pre> //下载 64bit ndk-r9b-x86_64 64位 ndk r9b, * Download [64bit ndk-r9b-x86_64](http://dl.google.com/android/ndk/android-ndk-r9b-darwin-x86_64.tar.bz2) from [google](http://developer.android.com/tools/sdk/ndk/index.html) * Run //配置路径 <pre> export NDK_ROOT=/path/to/android-ndk-r9b ./genbindings.py </pre> //在 linux 12.04 64 位版本号 On Ubuntu Linux 12.04 64bit ------------ //通过命令行安装python * Install python <pre> sudo apt-get install python2.7 </pre> * Install python dependices by pip. <pre> sudo apt-get install python-pip sudo pip install PyYAML sudo pip install Cheetah </pre> //下载 64bit ndk-r9b-x86_64 64位 ndk r9b。下面同mac 操作系统 * Download [64bit ndk-r9b-x86_64]( https://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64.tar.bz2) from [google](http://developer.android.com/tools/sdk/ndk/index.html) * Go to "cocos2d-x/tools/tolua", Run <pre> export NDK_ROOT=/path/to/android-ndk-r9b ./genbindings.py </pre> 本文出自 http://blog.csdn.net/han1558249222 未经同意请勿转载 将自己定义的c++方法绑定到lua http://shahdza.blog.51cto.com/2410787/1568051 How to Use bindings-generator ================== //windows 环境下 On Windows: ------------ //安装android-ndk-r9b * Make sure that you have installed `android-ndk-r9b`. //下载 python2.7.3 * Download python2.7.3 (32bit) from (http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi). //把python安装路径配置到path(windows 环境变量配置) * Add the installed path of python (e.g. C:Python27) to windows environment variable named 'PATH'. //下载pyyaml而且安装 安装python路径的Lib目录下的site-packages目录下 * Download pyyaml from http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.7.exe and install it. //下载 pyCheetah 而且解压到安装python路径的Lib目录下的site-packages目录下 * Download pyCheetah from https://raw.github.com/dumganhar/my_old_cocos2d-x_backup/download/downloads/Cheetah.zip, unzip it to "C:Python27Libsite-packages" 设置ndk——root合法的环境变量 * Set environment variables (`NDK_ROOT`) * Go to "cocos2d-x/tools/tolua" folder, and run "genbindings.py". The generated codes will be under "cocosscriptingauto-generatedjs-bindings". //mac环境下 On MAC: ---------- //,mac 10.9的系统版本号已经默认安装好了python2.7。假设你的mac 没有安装好则使用pip工具安装 * The OSX 10.9 has a built-in python2.7 and if your os don't have python2.7 then use [Homebrew](http://brew.sh/) to install the python and use pip install the python dependencies. <pre> brew install python </pre> //安装python须要用到的库 通过一下命令 * Install python dependices by pip. <pre> //在命令行输入下面命令进行安装 sudo easy_install pip //安装pip sudo pip install PyYAML //安装 pyYAMl 成功时回有个successfully提示 sudo pip install Cheetah </pre> //下载 64bit ndk-r9b-x86_64 64位 ndk r9b, * Download [64bit ndk-r9b-x86_64](http://dl.google.com/android/ndk/android-ndk-r9b-darwin-x86_64.tar.bz2) from [google](http://developer.android.com/tools/sdk/ndk/index.html) * Run //配置路径 <pre> export NDK_ROOT=/path/to/android-ndk-r9b ./genbindings.py </pre> //在 linux 12.04 64 位版本号 On Ubuntu Linux 12.04 64bit ------------ //通过命令行安装python 下面同mac 操作系统配置 * Install python <pre> sudo apt-get install python2.7 </pre> * Install python dependices by pip. <pre> sudo apt-get install python-pip sudo pip install PyYAML sudo pip install Cheetah </pre> //下载 64bit ndk-r9b-x86_64 64位 ndk r9b。下面同mac 操作系统 * Download [64bit ndk-r9b-x86_64]( https://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64.tar.bz2) from [google](http://developer.android.com/tools/sdk/ndk/index.html) * Go to "cocos2d-x/tools/tolua", Run <pre> export NDK_ROOT=/path/to/android-ndk-r9b ./genbindings.py </pre> 本文出自 http://blog.csdn.net/han1558249222 未经同意请勿转载 将自己定义的c++方法绑定到lua 感谢 http://shahdza.blog.51cto.com/2410787/1568051