cocos2dx toLua 没有PyYAML的解决办法

原创 2015年07月11日 10:29:27

What's new

  • Add a prebuilt libclang3.4 in libclang/for mac, linux and windows.
  • If you want use the prebuilt licbclang3.4 work with Android NDK, then only the NDK r9b is can work corrently with it.

Requirements

  • python2.7
  • py-yaml
  • cheetah (for target language templates)
  • libclang, from clang 3.3 or later

Usage

Usage: generator.py [options] {configfile}

Options:
  -h, --help   show this help message and exit
  -s SECTION   sets a specific section to be converted
  -t TARGET    specifies the target vm. Will search for TARGET.yaml

Basically, you specify a target vm (spidermonkey is the only current target vm) and the section from the .ini file you want to generate code for.

Run the simple test with prebuilt libclang3.4

Included in this repository is a simple test. Use this to confirm the generator is working and that your environment is set up correctly.

NOTE

  • The test uses the prebuilt 3.4 libclang, so you should use Android NDK r9b.
  • The test uses <string> and <stdint.h> so you need a C++ implementation that provides these
  • Currently, the test script is setup to use the Android NDK's GNU libstdc++

Mac OS X

  • The OSX 10.9 has a built-in python2.7 and if your os don't have python2.7 then use Homebrewto install the python and use pip install the python dependencies.

    brew install python
    
  • Install python dependices by pip.

    sudo easy_install pip
    sudo pip install PyYAML
    sudo pip install Cheetah
    
  • Download 64bit ndk-r9b-x86_64 from google

  • If you are using python installed from other way, copy user.cfg.sample and rename it as user.cfg then set the absolute path to python PYTHON_BIN in user.cfg
  • Run follow command, it will generate a userconf.ini, and check the values in it if it occorus any error.
    export NDK_ROOT=/path/to/android-ndk-r9b
    ./test.sh
    

Ubuntu Linux 12.04 64bit

  • Install python
    sudo apt-get install python2.7
    
  • Install python dependices by pip.
    sudo apt-get install python-pip
    sudo pip install PyYAML
    sudo pip install Cheetah
    
  • Download 64bit ndk-r9b-x86_64 from google
  • If you are using python installed from other way, copy user.cfg.sample and rename it as user.cfg then set the absolute path to python PYTHON_BIN in user.cfg
  • Run follow command, it will generate a userconf.ini, and check the values in it if it occorus any error.
    export NDK_ROOT=/path/to/android-ndk-r9b
    ./test.sh
    

Windows 7 64bit

Expected output

Upon running the test you might see some warnings but should not see any errors.

The test will create a directory named simple_test_bindings that contains 3 files

  • A .hpp header file for the bindings class
  • A .cpp file implementing the bindings class
  • A .js file that documents how to call (from JavaScript) the methods the C++ class exposes

The .ini file

The .ini file is a simple text file specifying the settings for the code generator. Here's the default one, used for cocos2d-x

[cocos2d-x]
prefix = cocos2dx
events  = CCNode#onEnter CCNode#onExit
extra_arguments = -I../../cocos2dx/include -I../../cocos2dx/platform -I../../cocos2dx/platform/ios -I../../cocos2dx -I../../cocos2dx/kazmath/include -arch i386 -DTARGET_OS_IPHONE -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -x c++
headers = ../../cocos2dx/include/cocos2d.h
classes = CCSprite
functions = my_free_function

Required sections

  • prefix: the prefix for the project. Must be a valid identifier for the language of the target vm. Most of the time, the name will be intermixed between the class name and the function name, since all generated (probably) will be free functions, we do that in order to avoid name collition. The script will generate ${prefix}.cpp and ${prefix}.hpp as a result.
  • events: a list of identifiers in the form of ClassName#functionName that are events to be called from the native world to the target vm.
  • extra_arguments: extra arguments to pass to the clang interface. Basically you can think of this as the arguments to pass to the "compiler", so add as many as you need here. If you're targetting C++, make sure you add "-x c++" as the last argument to force C++ mode on a ".h" file. Otherwise, name your header files as ".hpp".
  • headers: list of headers to parse. Usually you add a single header that in turn #includes the rest of the files.
  • classes: the classes that will be parsed. Right not is just a string, but it will accept regular expressions
  • functions: space-separated list of free functions to be binded. Same as with classes, it will support regular expressions.
  • skip: a space-separated list of Classes::functions or just functions to not generate any code.

The templates

The generator is using Cheetah templates to create a more flexible generator. The way it was thought, is that for every target environment, you should provide with a way to generate the same C/C++ functionality. Every template has access to the proper meta information for the code or generator (function, classes, etc.)

Right now it's separated in the following set of templates:

  • prelude.c/.h: The header of the generated files.
  • ifunction.c/.h: The template for an instance function
  • ifunction_overloaded.c: The template for the implementation of an overloaded function. An overloaded function is exactly the same as a function, but it has an array of functions sharing the same name. The current implementation for spidermonkey only works if the overloading is with different number of arguments.
  • sfunction.c/.h: The template for a static function
  • sfunction_overloaded.c: The template for an overloaded static function
  • register.c: Here you should add the constructor/finalizer, the registration function (if needed) and the footer of the header file. This is the last chunk being generated

Templates are stored in the templates/${target} directory and follow the naming specified above.

One final part of the puzzle is the ${target}.yaml file, that contains specific type conversion snippets to be used by the templates. For instance, for spidermonkey, this is the place where we specify the conversion routines for the native types (to and from int, float, string, etc.)

Limitations

Currently the generator is leveraging clang in order to get information about the C/C++ code, so we can only get as much information as clang give us. Known list of things that won't work:

  • variable number of arguments. Solution: write a manual wrapper

Cocos2d-x3.0 解压zip

2dx3.0为我们集成了unzip库,帮助我们实现对文件的
  • qqMCY
  • qqMCY
  • 2014年05月03日 20:02
  • 6367

cocos2dx v3.x C++绑定lua

本文转自:http://www.cocoachina.com/bbs/read.php?tid=200145  感谢作者分享。 嗳,侥天之幸初阶段游戏的 prototype 终于忽弄过去了!!! ...
  • jbhand
  • jbhand
  • 2015年03月12日 12:43
  • 1320

【COCOS2DX-LUA 脚本开发之十四】解决自定义CPP类通过TOLUA++ BINDING LUACOCOS2D后编译到ANDROID运行黑屏(没有调用自定义CPP类)的问题!

本站文章均为 李华明Himi 原创,转载务必在明显处注明:(作者新浪微博: @李华明Himi ) 转载自【黑米GameDev街区】 原文链接: http://www.himigame.com/lua-...

android 下 cocos2dx 后台黑屏的解决办法

问题描述:1.运行游戏,无问题 2.游戏点击网站链接,或进入后台,回来黑屏 3.eclipse控制台报错: 03-01 17:51:55.347: W/Adreno-ES20(8664): : G...
  • zszeng
  • zszeng
  • 2016年03月01日 21:36
  • 4016

cocos2dx js 关于canvas绘图模糊问题及解决办法

最近做了一个项目,发现同一张图,在大部分安卓手机里图片很模糊,而在ios设备里显示清晰。开始我以为是图片的问题或者是手机性能的原因,但即使把图片做的再大,再清楚也还是模糊。 为此苦恼了好几天。 后...

cocos2dx返回Android游戏黑屏解决办法

用Cocos-2dx搞一个游戏,但是要调用到java代码,java代码里面需要从cocos的activity切换到其他的activtiy(如A,B),切换回cocos的activity的时候,会遇到短...

新建cocos2dx开发遇到问题及解决办法

(1) f:\ddz pro\demo\demo\proj.win32\main.h(11): fatal error C1083: 无法打开包括文件:“CCStdC.h”: No such file...

初次安装cocos2dx所遇到的问题以及解决办法

从今天开始就要研究cocos2dx了,今天刚刚开始。刚刚装完系统,安装好vs2010后,下载cocos2dx解压后,打开里面vs2010的工程后就调试出现10个相同的错误:  正在创建库 E:\co...

【游戏开发备注之一】关于Cocos2dx_v1.x版本iphone与Android运行出现图片白块、添加GameCenter报错问题及编译Android闪退的解决办法&&CCLOG与CClog的区别

本站文章均为 李华明Himi 原创,转载务必在明显处注明:转载自【黑米GameDev街区】 原文链接: http://www.himigame.com/game-detail/1035.html   ...

[lua/unity/cocos2dx]关于云风pbc不支持int64的解决办法

其实这个很简单,因为源码都有,改改就好,但是估计有些人很担心改了之后出现各种问题解决不了,我通常是先改,出问题再说,哈哈。不过其实去看看源码,云风的代码还是写的很清晰的 以上是废话 找到pbc-l...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:cocos2dx toLua 没有PyYAML的解决办法
举报原因:
原因补充:

(最多只允许输入30个字)