cocos2d-js3.5 automatically bind C + + to JS on Mac

Source: Internet
Author: User

According to the official tutorial will also have problems, now put the problem record, in order to avoid the same problem later do not know what to do

According to the guidance inside the Readme.txt, the need to install the software are generally relatively simple, only need to enter a few commands.

At the end of the article there will be a specific content of the README.

Then enter the terminal input in turn

/bin/bash

Export ndk_root=/path/to/android-ndk-r9b

Sh./test.sh

There is a problem. As follows:

Missingsectionheadererror:file contains no section headers.

File:userconf.ini, Line:1

'-E [default]\n '

We need to modify the tesh.sh script.

Open any editor,

Put 112 lines of

Echo-e "$_contents" > "$_conf_ini_file"

Change to:

echo "$_contents" > "$_conf_ini_file"

Can.

The re-execution of SH test.sh should be successful.

-------readme.txt----------------

# 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 the Android ndk and then ' only the NDK r9b are 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 sections to be converted
-T target specifies the target VM. Would search for Target.yaml

Basically, you specify a target VM (SpiderMonkey are the only current target VM) and the sections from
The '. ini ' file want to generate code for.

# # Run The simple test with prebuilt libclang3.4

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

# # # NOTE

* The test uses the prebuilt 3.4 Libclang, so your should use ' Android NDK r9b '.
* The test uses <string> <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 had python2.7 then use [Homebrew] (http://brew.sh/) to instal L The Python and use pip install the Python dependencies.
<pre>
Brew Install Python
</pre>

* Install python dependices by Pip.
<pre>
sudo easy_install pip
sudo pip install Pyyaml
sudo pip install Cheetah
</pre>

* 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)
* If you is using Python installed from other, 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'll generate a ' userconf.ini ', and check the values in it if it occorus any error.
<pre>
Export ndk_root=/path/to/android-ndk-r9b
./test.sh
</pre>

# # # Ubuntu Linux 12.04 64bit
* 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
* 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)
* If you is using Python installed from the other , 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'll generate a ' userconf.ini ', and check the values in it if it occorus any error.
<pre>
Export ndk_root=/path/to/android-ndk-r9b
./test.sh
</pre>

# # Windows 7 64bit
* Download python2.7.3 (' 32bit ') from (Http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi).
* ADD the installed path of Python (e.g. C:\Python27) to Windows environment variable named ' path '.
* Download Pyyaml from Http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.7.exe and install it.
* Download Pycheetah from Https://raw.github.com/dumganhar/my_old_cocos2d-x_backup/download/downloads/Cheetah.zip, Unzip it to "C:\Python27\Lib\site-packages"
* Download [64bit ndk-r9b] (http://dl.google.com/android/ndk/android-ndk-r9b-windows-x86_64.zip) from [Google] (http ://developer.android.com/tools/sdk/ndk/index.html)
* Set the environment variables (' python_root ' and ' ndk_root ') or just them in ' test.bat '.
* Run "Test.bat". The generated codes would be under "simple_test_bindings".

# # Expected output

Upon running the "test you might see some warnings" but should don't see any errors.

The test would 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 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 is a valid identifier for the language of the target VM.
Most of the time, the name would be intermixed between the class name and the function name, since
All generated (probably) would be a free functions, we do, and order to avoid name collition. The
Script would generate ${prefix}.cpp and ${prefix}.hpp as a result.
* EVENTS:A List of identifiers in the form of classname#functionname that is events to be called
From the native world to the target VM.
* Extra_arguments:extra arguments to pass to the Clang interface. Basically 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 this in turn ' #include ' s the
Rest of the files.
* Classes:the classes that'll be parsed. Right isn't just a string, but it'll accept regular
Expressions
* functions:space-separated List of free functions to be binded. Same as with classes, it'll
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] (http://www.cheetahtemplate.org/) to create a more
Flexible generator. The It was thought, it's that for every target environment, and you should provide
With a-by-generate the same-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 a overloaded function. An
Overloaded function was exactly the same as a function, but it had an array of functions sharing
The same name. The current implementation for SpiderMonkey only works if the overloading are 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. The last chunk being generated

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

One final part of the puzzle are the ' ${target}.yaml ' file, that's contains specific type conversion
Snippets to is used by the templates. For instance, for SpiderMonkey, the the Where we
Specify the conversion routines for the native types (to and from int, float, string, etc.)

# Limitations

Currently the generator is leveraging clang on order to get information about the 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-js3.5 automatically bind C + + to JS on Mac

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.