初始化

This commit is contained in:
SmallMain
2022-06-25 00:23:03 +08:00
commit ef0589e8e5
2264 changed files with 617829 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
.DS_Store
gen/
*.pyc
test/user.cfg
test/userconf.ini
test/simple_test_bindings/
.idea
.swp

View File

@@ -0,0 +1,37 @@
Core Developers:
Rolando Abarca (funkaster)
The original author of repo
Surith Thekkiam (folecr)
James Chen (dumganhar)
The main maintainer
samuele3hu
Added lua target support
Dhilan007
pandamicro
Developers:
rohankuruvillak
The maintainer of this repo
carlomorgantinizynga
new manual conversion for type ccFontDefinition
jdmunro
Fixed an issue where cocos2d-x specific functionality was not appropriately wrapped with an #ifdef in binding code generated for default class constructors.
led42
Fixed native objects were left allocated with no references by the finalise routine
colesbury
Generated conversion from JS functions to std::function
lihex
Better support for Windows
dplusic
Fixed incorrect regular expression for std::function return type

View File

@@ -0,0 +1,168 @@
# What's new
* Add a prebuilt libclang 5.0 in `libclang/`for mac, linux and windows.
* If you want use the prebuilt licbclang 5.0 work with Android NDK, then `only the NDK r16 (or higher version) can work corrently` with it.
# Requirements
* python2.7
* py-yaml
* cheetah (for target language templates)
* libclang binary files
# 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.
### Download libclang binary files
* Go to website [http://releases.llvm.org/download.html#5.0.0](http://releases.llvm.org/download.html#5.0.0)
* Download `Pre-Built Binaries` according your platforms
* Unzip or install binaries. For example, unzip `clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz` for macOS.
* Find libclang.dll (windows) or libclang.dylib (macOS)
* Copy the dynamic library to `bindings-generator/libclang` folder.
## Run the simple test with prebuilt libclang 5.0
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 5.0 libclang, so you should use `Android NDK r16` or higher version.
* 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 llvm libc++
### Mac OS X
* 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>
* Install python dependices by pip.
<pre>
sudo easy_install pip
sudo pip install PyYAML
sudo pip install Cheetah
</pre>
* Download [NDK r16](https://dl.google.com/android/repository/android-ndk-r16-darwin-x86_64.zip) from [google](https://developer.android.com/ndk/downloads/index.html)
* 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.
<pre>
export NDK_ROOT=/path/to/android-ndk-r16
./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 [NDK r16](https://dl.google.com/android/repository/android-ndk-r16-linux-x86_64.zip) from [google](https://developer.android.com/ndk/downloads/index.html)
* 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.
<pre>
export NDK_ROOT=/path/to/android-ndk-r16
./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 [Cheetah-2.4.4.tar.gz](https://pypi.python.org/packages/cd/b0/c2d700252fc251e91c08639ff41a8a5203b627f4e0a2ae18a6b662ab32ea/Cheetah-2.4.4.tar.gz#md5=853917116e731afbc8c8a43c37e6ddba), extract and install it by `python setup.py`.
* Download [NDK r16](https://dl.google.com/android/repository/android-ndk-r16-windows-x86_64.zip) from [google](https://developer.android.com/ndk/downloads/index.html)
* Set the environment variables (`PYTHON_ROOT` and `NDK_ROOT`) or just them in `test.bat`.
* Run "test.bat". The generated codes will be under "simple_test_bindings".
### 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 `#include`s 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](http://www.cheetahtemplate.org/) 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

View File

@@ -0,0 +1,24 @@
#===- __init__.py - Clang Python Bindings --------------------*- python -*--===#
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
#===------------------------------------------------------------------------===#
r"""
Clang Library Bindings
======================
This package provides access to the Clang compiler and libraries.
The available modules are:
cindex
Bindings for the Clang indexing library.
"""
__all__ = ['cindex']

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,34 @@
#===- enumerations.py - Python Enumerations ------------------*- python -*--===#
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
#===------------------------------------------------------------------------===#
"""
Clang Enumerations
==================
This module provides static definitions of enumerations that exist in libclang.
Enumerations are typically defined as a list of tuples. The exported values are
typically munged into other types or classes at module load time.
All enumerations are centrally defined in this file so they are all grouped
together and easier to audit. And, maybe even one day this file will be
automatically generated by scanning the libclang headers!
"""
# Maps to CXTokenKind. Note that libclang maintains a separate set of token
# enumerations from the C++ API.
TokenKinds = [
('PUNCTUATION', 0),
('KEYWORD', 1),
('IDENTIFIER', 2),
('LITERAL', 3),
('COMMENT', 4),
]
__all__ = ['TokenKinds']

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
libclang in LLVM 5.0.0

View File

@@ -0,0 +1,192 @@
definitions:
# the names of the functions - we use this to generate the code and to register the functions in
# the javascript class
ifunction: "js_${generator.prefix}_${class_name}_${func_name}"
sfunction: "js_${generator.prefix}_${class_name}_${func_name}"
constructor: "js_${generator.prefix}_${class_name}_constructor"
ctor: "js_${generator.prefix}_${class_name}_ctor"
public_field: "js_${generator.prefix}_${class_name}"
conversions:
# some times you want to use a special native type when converting from spidermonkey to native
# the most common case would be from JS-boolean to bool. Using "bool" will fail here since we
# pass the address to the conversion method, and a JSBool is defined as an integer in spidermonkey
native_types:
# float: "double"
short: "int16_t"
"unsigned char": "uint8_t"
"char": "int8_t"
ns_map:
"cocos2d::extension::": "cc."
"cocos2d::ui::": "ccui."
"cocos2d::": "cc."
"spine::": "sp."
"cocostudio::": "ccs."
"cocosbuilder::": "cc."
"CocosDenshion::": "cc."
to_native:
# jsval to int
int32_t: "ok &= seval_to_int32(${in_value}, (int32_t*)&${out_value})"
# int: "ok &= seval_to_int32(${in_value}, (int32_t*)&${out_value})"
int: "do { int32_t tmp = 0; ok &= seval_to_int32(${in_value}, &tmp); ${out_value} = (${arg_type})tmp; } while(false)"
"unsigned int": "ok &= seval_to_uint32(${in_value}, (uint32_t*)&${out_value})"
"unsigned char": "ok &= seval_to_uint8(${in_value}, (uint8_t*)&${out_value})"
short: "ok &= seval_to_int16(${in_value}, &${out_value})"
"unsigned short": "ok &= seval_to_uint16(${in_value}, &${out_value})"
char: "ok &= seval_to_int8(${in_value}, (int8_t*)&${out_value})"
bool: "ok &= seval_to_boolean(${in_value}, &${out_value})"
float: "ok &= seval_to_float(${in_value}, &${out_value})"
double: "ok &= seval_to_double(${in_value}, &${out_value})"
long: "ok &= seval_to_long(${in_value}, &${out_value})"
"unsigned long": "ok &= seval_to_ulong(${in_value}, &${out_value})"
"ssize_t": "ok &= seval_to_ssize(${in_value}, &${out_value})"
"size_t": "ok &= seval_to_size(${in_value}, &${out_value})"
# jsval has to be a TypedArray, a UInt32Array with 2 elements
"long long": "ok &= seval_to_longlong(${in_value}, &${out_value})"
"string": "ok &= seval_to_std_string(${in_value}, &${out_value})"
"char*": "std::string ${out_value}_tmp; ok &= seval_to_std_string(${in_value}, &${out_value}_tmp); ${out_value} = ${out_value}_tmp.c_str()"
"Point": "ok &= seval_to_Vec2(${in_value}, &${out_value})"
"Rect": "ok &= seval_to_Rect(${in_value}, &${out_value})"
"Size": "ok &= seval_to_Size(${in_value}, &${out_value})"
"Color4B": "ok &= seval_to_Color4B(${in_value}, &${out_value})"
"Color4F": "ok &= seval_to_Color4F(${in_value}, &${out_value})"
"Color3B": "ok &= seval_to_Color3B(${in_value}, &${out_value})"
"Color3F": "ok &= seval_to_Color3F(${in_value}, &${out_value})"
# "Array*": "ok &= seval_to_ccarray(${in_value}, &${out_value})"
# "Dictionary*": "ok &= seval_to_ccdictionary(${in_value}, &${out_value})"
"AffineTransform": "ok &= seval_to_AffineTransform(${in_value}, &${out_value})"
"FontDefinition": "ok &= seval_to_FontDefinition(${in_value}, &${out_value})"
"String*": "std::string ${out_value}_tmp; ok &= seval_to_std_string(${in_value}, &${out_value}_tmp); ${out_value} = cocos2d::String::create(${out_value}_tmp)"
"@Vector<.*>": "ok &= seval_to_Vector(${in_value}, &${out_value})"
"@Map<std::string.*>": "ok &= seval_to_Map_string_key(${in_value}, &${out_value})"
"@map<std::string.*,\\s*std::string.*>": "ok &= seval_to_std_map_string_string(${in_value}, &${out_value})"
"Value": "ok &= seval_to_ccvalue(${in_value}, &${out_value})"
"ValueMap": "ok &= seval_to_ccvaluemap(${in_value}, &${out_value})"
"ValueMapIntKey": "ok &= seval_to_ccvaluemapintkey(${in_value}, &${out_value})"
"ValueVector": "ok &= seval_to_ccvaluevector(${in_value}, &${out_value})"
"@vector<std::string.*>": "ok &= seval_to_std_vector_string(${in_value}, &${out_value})"
"@vector<int.*>": "ok &= seval_to_std_vector_int(${in_value}, &${out_value})"
"@vector<float.*>": "ok &= seval_to_std_vector_float(${in_value}, &${out_value})"
"@vector<.*Texture.*>": "ok &= seval_to_std_vector_Texture(${in_value}, &${out_value})"
"@vector<.*RenderTarget.*>": "ok &= seval_to_std_vector_RenderTarget(${in_value}, &${out_value})"
"vector<std::unordered_map<std::string, cocos2d::Value>>": "ok &= seval_to_EffectDefineTemplate(${in_value}, &${out_value})"
"unordered_map<std::string, cocos2d::renderer::Technique::Parameter>": "ok &= seval_to_EffectProperty(${in_value}, &${out_value})"
"Acceleration": "ok &= seval_to_Acceleration(${in_value}, &${out_value})"
"Parameter": "ok &= seval_to_TechniqueParameter(${in_value}, &${out_value})"
"vector<cocos2d::renderer::Technique::Parameter>": "ok &= seval_to_std_vector_TechniqueParameter(${in_value}, &${out_value})"
"vector<cocos2d::renderer::ProgramLib::Template>": "ok &= seval_to_std_vector_ProgramLib_Template(${in_value}, &${out_value})"
"Mat4": "ok &= seval_to_Mat4(${in_value}, &${out_value})"
"Vec2": "ok &= seval_to_Vec2(${in_value}, &${out_value})"
"Vec3": "ok &= seval_to_Vec3(${in_value}, &${out_value})"
"Vec2*": "std::vector<cocos2d::Vec2> tempData;ok &= seval_to_std_vector_Vec2(${in_value}, &tempData);${out_value}=tempData.data()"
"BlendFunc": "ok &= seval_to_blendfunc(${in_value}, &${out_value})"
"_ttfConfig": "ok &= seval_to_TTFConfig(${in_value}, &${out_value})"
"TTFConfig": "ok &= seval_to_TTFConfig(${in_value}, &${out_value})"
# "AnimationInfo": "ok &= seval_to_animationInfo(${in_value}, &${out_value})"
"Quaternion": "ok &= seval_to_Quaternion(${in_value}, &${out_value})"
# "Ray": "ok &= seval_to_ray(${in_value}, &${out_value})"
# "NavMeshAgentParam": "ok &= seval_to_NavMeshAgentParam(${in_value}, &${out_value})"
# "Physics3DRigidBodyDes*": "cocos2d::Physics3DRigidBodyDes tempObj;${out_value}=&tempObj;ok &= seval_to_physics3DRigidBodyDes(${in_value}, ${out_value})"
# "TerrainData": "ok &= seval_to_TerrainData(${in_value}, &${out_value})"
"TMXTileFlags_": "ok &= seval_to_uint32(${in_value}, (uint32_t *)&${out_value})"
"TMXTileFlags_*": "uint32_t tempData;${out_value}=(cocos2d::TMXTileFlags_*)&tempData;ok &= seval_to_uint32(${in_value}, (uint32_t *)&${out_value})"
"ResourceData": "ok &= seval_to_ResourceData(${in_value}, &${out_value})"
"ListenerID": "ok &= seval_to_std_string(${in_value}, &${out_value})"
"DownloaderHints": "ok &= seval_to_DownloaderHints(${in_value}, &${out_value})"
"Viewport": "ok &= seval_to_Viewport(${in_value}, &${out_value})"
"Data": "ok &= seval_to_Data(${in_value}, &${out_value})"
"b2Vec2": "ok &= seval_to_b2Vec2(${in_value}, &${out_value})"
"b2AABB": "ok &= seval_to_b2AABB(${in_value}, &${out_value})"
"Options": "ok &= seval_to_TextureOptions(${in_value}, &${out_value})"
"SubImageOption": "ok &= seval_to_TextureSubImageOption(${in_value}, &${out_value})"
"ImageOption": "ok &= seval_to_TextureImageOption(${in_value}, &${out_value})"
"String": "${out_value} = ${in_value}.toStringForce().c_str()"
"@Vector<spine::String.*>": "ok &= seval_to_spine_Vector_String(${in_value}, &${out_value})"
"@Vector<spine::((?!String).)*>": "ok &= seval_to_spine_Vector_T_ptr(${in_value}, &${out_value})"
"se_object_ptr": "${out_value} = ${in_value}.toObject()"
object: "ok &= seval_to_native_ptr(${in_value}, &${out_value})"
from_native:
# int to jsval
int32_t: "ok &= int32_to_seval(${in_value}, &${out_value})"
int: "ok &= int32_to_seval(${in_value}, &${out_value})"
enum: "ok &= int32_to_seval(${in_value}, &${out_value})"
"unsigned int": "ok &= uint32_to_seval(${in_value}, &${out_value})"
"unsigned short": "ok &= int16_to_seval(${in_value}, &${out_value})"
"unsigned char": "ok &= uint8_to_seval(${in_value}, &${out_value})"
"char": "ok &= int8_to_seval(${in_value}, &${out_value})"
"long long": "ok &= longlong_to_seval(${in_value}, &${out_value})"
"string": "ok &= std_string_to_seval(${in_value}, &${out_value})"
"string&": "ok &= std_string_to_seval(${in_value}, &${out_value})"
"char*": "ok &= std_string_to_seval(${in_value}, &${out_value})"
bool: "ok &= boolean_to_seval(${in_value}, &${out_value})"
float: "ok &= float_to_seval(${in_value}, &${out_value})"
double: "ok &= double_to_seval(${in_value}, &${out_value})"
long: "ok &= long_to_seval(${in_value}, &${out_value})"
"unsigned long": "ok &= ulong_to_seval(${in_value}, &${out_value})"
"ssize_t": "ok &= ssize_to_seval(${in_value}, &${out_value})"
"ssize_t": "ok &= size_to_seval(${in_value}, &${out_value})"
"Point": "ok &= Vec2_to_seval(${in_value}, &${out_value})"
"Rect": "ok &= Rect_to_seval(${in_value}, &${out_value})"
"Size": "ok &= Size_to_seval(${in_value}, &${out_value})"
"Color4B": "ok &= Color4B_to_seval(${in_value}, &${out_value})"
"Color4F": "ok &= Color4F_to_seval(${in_value}, &${out_value})"
"Color3B": "ok &= Color3B_to_seval(${in_value}, &${out_value})"
"Color3F": "ok &= Color3F_to_seval(${in_value}, &${out_value})"
# "Array*": "${out_value} = ccarray_to_seval(${in_value})"
# "Dictionary*": "${out_value} = ccdictionary_to_seval(${in_value})"
"AffineTransform": "ok &= AffineTransform_to_seval(${in_value}, &${out_value})"
"FontDefinition": "ok &= FontDefinition_to_seval(${in_value}, &${out_value})"
# "String*": "${out_value} = std_string_to_seval(${in_value}->getCString())"
"@Vector<.*>": "ok &= Vector_to_seval(${in_value}, &${out_value})"
"@Map<std::string.*>": "ok &= Map_string_key_to_seval(${in_value}, &${out_value})"
"@map<std::string.*,\\s*std::string.*>": "ok &= std_map_string_string_to_seval(${in_value}, &${out_value})"
"Value": "ok &= ccvalue_to_seval(${in_value}, &${out_value})"
"ValueMap": "ok &= ccvaluemap_to_seval(${in_value}, &${out_value})"
"ValueMapIntKey": "ok &= ccvaluemapintkey_to_seval(${in_value}, &${out_value})"
"ValueVector": "ok &= ccvaluevector_to_seval(${in_value}, &${out_value})"
"@vector<std::string.*>": "ok &= std_vector_string_to_seval(${in_value}, &${out_value})"
"@vector<int.*>": "ok &= std_vector_int_to_seval(${in_value}, &${out_value})"
"@vector<float.*>": "ok &= std_vector_float_to_seval(${in_value}, &${out_value})"
"@vector<.*Touch.*>": "ok &= std_vector_Touch_to_seval(${in_value}, &${out_value})"
"@vector<.*RenderTarget.*>": "ok &= std_vector_RenderTarget_to_seval(${in_value}, &${out_value})"
"Acceleration*": "ok &= Acceleration_to_seval(${in_value}, &${out_value})"
"Parameter": "ok &= TechniqueParameter_to_seval(${in_value}, &${out_value})"
"vector<cocos2d::renderer::Technique::Parameter>": "ok &= std_vector_TechniqueParameter_to_seval(${in_value}, &${out_value})"
"Mat4": "ok &= Mat4_to_seval(${in_value}, &${out_value})"
"Vec2": "ok &= Vec2_to_seval(${in_value}, &${out_value})"
"Vec3": "ok &= Vec3_to_seval(${in_value}, &${out_value})"
"Vec4": "ok &= Vec4_to_seval(${in_value}, &${out_value})"
"BlendFunc": "ok &= blendfunc_to_seval(${in_value}, &${out_value})"
"Quaternion": "ok &= Quaternion_to_seval(${in_value}, &${out_value})"
"spEventData*": "ok &= speventdata_to_seval(${in_value}, &${out_value})"
"spEvent*": "ok &= spevent_to_seval(${in_value}, &${out_value})"
"spBoneData*": "ok &= spbonedata_to_seval(${in_value}, &${out_value})"
"spBone*": "ok &= spbone_to_seval(${in_value}, &${out_value})"
"spSkeleton*": "ok &= spskeleton_to_seval(${in_value}, &${out_value})"
"spAttachment*": "ok &= spattachment_to_seval(${in_value}, &${out_value})"
"spSlotData*": "ok &= spslotdata_to_seval(${in_value}, &${out_value})"
"spSlot*": "ok &= spslot_to_seval(${in_value}, &${out_value})"
"spTimeline*": "ok &= sptimeline_to_seval(${in_value}, &${out_value})"
"spAnimationState*": "ok &= spanimationstate_to_seval(${in_value}, &${out_value})"
"spAnimation*": "ok &= spanimation_to_seval(${in_value}, &${out_value})"
"spTrackEntry*": "ok &= sptrackentry_to_seval(${in_value}, &${out_value})"
# "OffMeshLinkData": "${out_value} = offMeshLinkData_to_seval(${in_value})"
"TouchEventType": "ok &= int32_to_seval((int32_t)${in_value}, &${out_value})"
"EventType": "ok &= int32_to_seval((int32_t)${in_value}, &${out_value})"
"ManifestAsset": "ok &= ManifestAsset_to_seval(${in_value}, &${out_value})"
"@DownloadTask.*": "ok &= DownloadTask_to_seval(${in_value}, &${out_value})"
"@shared_ptr<.*DownloadTask.*": "ok &= DownloadTask_to_seval(*${in_value}, &${out_value})"
"Viewport": "ok &= Viewport_to_seval(${in_value}, &${out_value})"
"Data": "ok &= Data_to_seval(${in_value}, &${out_value})"
"b2Vec2": "ok &= b2Vec2_to_seval(${in_value}, &${out_value})"
"b2Manifold*": "ok &= b2Manifold_to_seval(${in_value}, &${out_value})"
"b2AABB": "ok &= b2AABB_to_seval(${in_value}, &${out_value})"
"VertexFormat": "ok &= VertexFormat_to_seval(${in_value}, &${out_value})"
"se_object_ptr": "${out_value}.setObject(${in_value})"
"String": "${out_value}.setString(${in_value}.buffer())"
"@(?:\\bBoneData\\b|\\bSkeleton\\b|\\bColor\\b|\\bEventData\\b|\\bIkConstraintData\\b|\\bPathConstraintData\\b|\\bTransformConstraintData\\b|\\bBone\\b|\\bSlotData\\b)+(?!\\*)+": "ok &= native_ptr_to_rooted_seval<${ntype.replace('const ', '').replace('&', '')}>((${ntype.replace('const ', '').replace('&', '')}*)&${in_value}, &${out_value})"
"@Vector<spine::((?!String).)*>": "ok &= spine_Vector_T_ptr_to_seval(${in_value}, &${out_value})"
"@Vector<.*(\\bshort\\b|\\bfloat\\b)+>": "ok &= spine_Vector_T_to_seval(${in_value}, &${out_value})"
"@Vector<spine::String.*>": "ok &= spine_Vector_String_to_seval(${in_value}, &${out_value})"
object: "ok &= native_ptr_to_seval<${ntype.replace('*', '').replace('const ', '')}>((${ntype.replace('const ', '')})${in_value}, &${out_value})"
rooted_object: "ok &= native_ptr_to_rooted_seval<${ntype.replace('*', '').replace('const ', '')}>((${ntype.replace('const ', '')})${in_value}, &${out_value})"

View File

@@ -0,0 +1,11 @@
#set generator = $current_class.generator
/**
* @class ${current_class.class_name}
*/
#if $generator.target_ns
${generator.target_ns}.${current_class.target_class_name} = {
#else
${current_class.target_class_name} = {
#end if

View File

@@ -0,0 +1,40 @@
/**
* @method ${func_name}
#if $is_constructor
* @constructor
#end if
#if $min_args > 0
#set $count = 0
#for $arg in $arguments
#set $argValue = "arg" + str(count)
* @param {$generator.js_typename_from_natve($arg.namespaced_class_name)} $argValue
#set $count = $count + 1
#end for
#end if
#if str($ret_type) != "void"
* @return {$generator.js_typename_from_natve($ret_type.namespaced_class_name)}
#end if
*/
${func_name} : function (
#if $min_args > 0
#set $length = len($arguments)
#set $index = 0
#for $arg in $arguments
#set $argname = $arg.name.replace("*", "").replace("const ", "")
#if $index < $length - 1
$generator.api_param_name_from_native(argname),
#else
$generator.api_param_name_from_native(argname)
#end if
#set $index = $index + 1
#end for
#end if
)
{
#if str($ret_type) != "void"
#set $is_enum = $ret_type.is_enum
#set $ret = $ret_type.namespaced_class_name.replace("*", "").replace("const ", "")
return $generator.js_ret_name_from_native($ret,$is_enum);
#end if
},

View File

@@ -0,0 +1,102 @@
/**
* @method ${func_name}
#if $is_constructor
* @constructor
#end if
#set $max_count = 0
#set $func_count = len($implementations)
#set $func_index = 0
#for func in $implementations
#if len($func.arguments) >= $max_count
#set $max_count = len($func.arguments)
#end if
#set $func_index = $func_index + 1
#end for
#if $max_count > 0
#set $arg_idx = 0
#while $arg_idx < $max_count
#set $tip = "@param {"
#set $sub_tip = ""
#set $is_sub_tip_set = False
#set $func_index = 0
#for func in $implementations
#set $loop_index = 0
#set $is_find = False
#for $arg in $func.arguments
#if $loop_index < len($func.arguments)
#if $loop_index == $arg_idx
#set $tip = $tip + $generator.js_typename_from_natve($arg.namespaced_class_name)
#set $is_find = True
#if $is_sub_tip_set == False
#set $is_sub_tip_set = True
#set $sub_tip = $generator.api_param_name_from_native($arg.name.replace("*", "").replace("const ", ""))
#end if
#end if
#set $loop_index = $loop_index + 1
#end if
#end for
#if $func_index < $func_count - 1
#if $is_find == True
#set $tip = $tip + "|"
#end if
#end if
#set $func_index = $func_index + 1
#end for
#if $tip.endswith('|')
#set $tip = $tip[:-1]
#end if
#set $tip = $tip + "} " + $sub_tip
* $tip
#set $arg_idx = $arg_idx + 1
#end while
#end if
#set $ret_tip = "{"
#set $func_index = 0
#set $have_ret = False
#for func in $implementations
#if str($func.ret_type) != "void"
#set $ret_tip = $ret_tip + $generator.js_typename_from_natve($func.ret_type.namespaced_class_name) + "|"
#set $have_ret = True
#end if
#set $func_index = $func_index + 1
#end for
#if $ret_tip.endswith('|')
#set $ret_tip = $ret_tip[:-1] + "}"
#end if
#if $have_ret
* @return $ret_tip
#end if
*/
#set $max_count = 0
#set $func_count = len($implementations)
#set $func_index = 0
#set $max_index = 0
#set $selected_func = 0
#for func in $implementations
#if len($func.arguments) >= $max_count
#set $max_count = len($func.arguments)
#set $max_index = $func_index
#set $selected_func = func
#end if
#set $func_index = $func_index + 1
#end for
${func_name} : function(
#set $arg_idx = 0
#for $arg in $selected_func.arguments
#set $argname = $arg.name.replace("*", "").replace("const ", "")
#if $arg_idx < $max_count - 1
$generator.api_param_name_from_native(argname),
#else
$generator.api_param_name_from_native(argname)
#end if
#set $arg_idx = $arg_idx + 1
#end for
)
{
#if str($selected_func.ret_type) != "void"
#set $is_enum = $selected_func.ret_type.is_enum
#set $ret = $selected_func.ret_type.namespaced_class_name.replace("*", "").replace("const ", "")
return $generator.js_ret_name_from_native($ret,$is_enum);
#end if
},

View File

@@ -0,0 +1,12 @@
#if $target_ns
#if $prefix
/**
* @module ${prefix}
*/
#else
/**
* @module ${target_ns}
*/
#end if
var ${target_ns} = ${target_ns} || {};
#end if

View File

@@ -0,0 +1,56 @@
## ===== constructor function implementation template
SE_DECLARE_FINALIZE_FUNC(js_${underlined_class_name}_finalize)
static bool ${signature_name}(se::State& s)
{
#if len($arguments) >= $min_args
#set arg_count = len($arguments)
#set arg_idx = $min_args
#set $count = 0
#if $arg_idx > 0
CC_UNUSED bool ok = true;
const auto& args = s.args();
#end if
#while $count < $arg_idx
#set $arg = $arguments[$count]
#set $arg_type = arg.to_string($generator)
#if $arg.is_numeric
$arg_type arg${count} = 0;
#elif $arg.is_pointer
$arg_type arg${count} = nullptr;
#else
$arg_type arg${count};
#end if
#set $count = $count + 1
#end while
#set $count = 0
#set arg_list = ""
#set arg_array = []
#while $count < $arg_idx
#set $arg = $arguments[$count]
#set $arg_type = arg.to_string($generator)
${arg.to_native({"generator": $generator,
"arg_type": $arg_type,
"in_value": "args[" + str(count) + "]",
"out_value": "arg" + str(count),
"class_name": $class_name,
"level": 2,
"is_static": False,
"ntype": str($arg)})};
#set $arg_array += ["arg"+str(count)]
#set $count = $count + 1
#end while
#if $arg_idx > 0
SE_PRECONDITION2(ok, false, "${signature_name} : Error processing arguments");
#end if
#set $arg_list = ", ".join($arg_array)
${namespaced_class_name}* cobj = new (std::nothrow) ${namespaced_class_name}($arg_list);
s.thisObject()->setPrivateData(cobj);
#if not $is_ref_class
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
#end if
#end if
return true;
}
SE_BIND_CTOR(${signature_name}, __jsb_${underlined_class_name}_class, js_${underlined_class_name}_finalize)

View File

@@ -0,0 +1,63 @@
## ===== constructor function implementation template
SE_DECLARE_FINALIZE_FUNC(js_${underlined_class_name}_finalize)
static bool ${signature_name}(se::State& s)
{
CC_UNUSED bool ok = true;
const auto& args = s.args();
size_t argc = args.size();
#for func in $implementations
#if len($func.arguments) >= $func.min_args
#set arg_count = len($func.arguments)
#set arg_idx = $func.min_args
#while $arg_idx <= $arg_count
#set arg_list = ""
#set arg_array = []
do {
#if $func.min_args >= 0
if (argc == $arg_idx) {
#set $count = 0
#while $count < $arg_idx
#set $arg = $func.arguments[$count]
#set $arg_type = arg.to_string($generator)
#if $arg.is_numeric
${arg_type} arg${count} = 0;
#elif $arg.is_pointer
${arg_type} arg${count} = nullptr;
#else
${arg_type} arg${count};
#end if
${arg.to_native({"generator": $generator,
"arg_type": $arg_type,
"in_value": "args[" + str(count) + "]",
"out_value": "arg" + str(count),
"class_name": $class_name,
"level": 3,
"is_static": False,
"is_persistent": $is_persistent,
"ntype": str($arg)})};
#set $arg_array += ["arg"+str(count)]
#set $count = $count + 1
#if $arg_idx > 0
if (!ok) { ok = true; break; }
#end if
#end while
#end if
#set $arg_list = ", ".join($arg_array)
${namespaced_class_name}* cobj = new (std::nothrow) ${namespaced_class_name}($arg_list);
s.thisObject()->setPrivateData(cobj);
#if not $is_ref_class
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
#end if
return true;
}
} while(false);
#set $arg_idx = $arg_idx + 1
#end while
#end if
#end for
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
return false;
}
SE_BIND_CTOR(${signature_name}, __jsb_${underlined_class_name}_class, js_${underlined_class_name}_finalize)

View File

@@ -0,0 +1,55 @@
## ===== ctor function implementation template
static bool ${signature_name}(se::State& s)
{
#if len($arguments) >= $min_args
#set arg_count = len($arguments)
#set arg_idx = $min_args
#set $count = 0
#if $arg_idx > 0
CC_UNUSED bool ok = true;
const auto& args = s.args();
#end if
#while $count < $arg_idx
#set $arg = $arguments[$count]
#set $arg_type = arg.to_string($generator)
#if $arg.is_numeric
${arg.to_string($generator)} arg${count} = 0;
#elif $arg.is_pointer
${arg.to_string($generator)} arg${count} = nullptr;
#else
${arg.to_string($generator)} arg${count};
#end if
#set $count = $count + 1
#end while
#set $count = 0
#set arg_list = ""
#set arg_array = []
#while $count < $arg_idx
#set $arg = $arguments[$count]
#set $arg_type = arg.to_string($generator)
${arg.to_native({"generator": $generator,
"arg_type": $arg_type,
"in_value": "args[" + str(count) + "]",
"out_value": "arg" + str(count),
"class_name": $class_name,
"level": 2,
"is_static": False,
"is_persistent": $is_persistent,
"ntype": str($arg)})};
#set $arg_array += ["arg"+str(count)]
#set $count = $count + 1
#end while
#if $arg_idx > 0
SE_PRECONDITION2(ok, false, "${signature_name} : Error processing arguments");
#end if
#set $arg_list = ", ".join($arg_array)
${namespaced_class_name}* cobj = new (std::nothrow) ${namespaced_class_name}($arg_list);
s.thisObject()->setPrivateData(cobj);
#if not $is_ref_class
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
#end if
#end if
return true;
}
SE_BIND_SUB_CLS_CTOR(${signature_name}, __jsb_${underlined_class_name}_class, js_${underlined_class_name}_finalize)

View File

@@ -0,0 +1,63 @@
## ===== constructor function implementation template
SE_DECLARE_FINALIZE_FUNC(js_${underlined_class_name}_finalize)
static bool ${signature_name}(se::State& s)
{
CC_UNUSED bool ok = true;
const auto& args = s.args();
size_t argc = args.size();
#for func in $implementations
#if len($func.arguments) >= $func.min_args
#set arg_count = len($func.arguments)
#set arg_idx = $func.min_args
#while $arg_idx <= $arg_count
#set arg_list = ""
#set arg_array = []
do {
#if $func.min_args >= 0
if (argc == $arg_idx) {
#set $count = 0
#while $count < $arg_idx
#set $arg = $func.arguments[$count]
#set $arg_type = arg.to_string($generator)
#if $arg.is_numeric
${arg_type} arg${count} = 0;
#elif $arg.is_pointer
${arg_type} arg${count} = nullptr;
#else
${arg_type} arg${count};
#end if
${arg.to_native({"generator": $generator,
"arg_type": $arg_type,
"in_value": "args[" + str(count) + "]",
"out_value": "arg" + str(count),
"class_name": $class_name,
"level": 3,
"is_static": False,
"is_persistent": $is_persistent,
"ntype": str($arg)})};
#set $arg_array += ["arg"+str(count)]
#set $count = $count + 1
#if $arg_idx > 0
if (!ok) { ok = true; break; }
#end if
#end while
#end if
#set $arg_list = ", ".join($arg_array)
${namespaced_class_name}* cobj = new (std::nothrow) ${namespaced_class_name}($arg_list);
s.thisObject()->setPrivateData(cobj);
#if not $is_ref_class
se::NonRefNativePtrCreatedByCtorMap::emplace(cobj);
#end if
return true;
}
} while(false);
#set $arg_idx = $arg_idx + 1
#end while
#end if
#end for
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
return false;
}
SE_BIND_SUB_CLS_CTOR(${signature_name}, __jsb_${underlined_class_name}_class, js_${underlined_class_name}_finalize)

View File

@@ -0,0 +1 @@
SE_DECLARE_FUNC(js_${generator.prefix}_${class_name}_${func_name});

View File

@@ -0,0 +1,76 @@
## ===== instance function implementation template
static bool ${signature_name}(se::State& s)
{
${namespaced_class_name}* cobj = (${namespaced_class_name}*)s.nativeThisObject();
SE_PRECONDITION2(cobj, false, "${signature_name} : Invalid Native Object");
#if len($arguments) >= $min_args
const auto& args = s.args();
size_t argc = args.size();
#set arg_count = len($arguments)
#set arg_idx = $min_args
#if $arg_count > 0 or $ret_type.name != "void"
CC_UNUSED bool ok = true;
#end if
#while $arg_idx <= $arg_count
if (argc == ${arg_idx}) {
#set $count = 0
#while $count < $arg_idx
#set $arg = $arguments[$count]
#set $arg_type = $arg.to_string($generator)
#if $arg.is_numeric
$arg_type arg${count} = 0;
#elif $arg.is_pointer
$arg_type arg${count} = nullptr;
#else
$arg_type arg${count};
#end if
#set $count = $count + 1
#end while
#set $count = 0
#set arg_list = ""
#set arg_array = []
#while $count < $arg_idx
#set $arg = $arguments[$count]
#set $arg_type = $arg.to_string($generator)
${arg.to_native({"generator": $generator,
"arg_type": $arg_type,
"in_value": "args[" + str(count) + "]",
"out_value": "arg" + str(count),
"class_name": $class_name,
"level": 2,
"is_static": False,
"is_persistent": $is_persistent,
"ntype": str($arg)})};
#set $arg_array += ["arg"+str(count)]
#set $count = $count + 1
#end while
#if $arg_idx > 0
SE_PRECONDITION2(ok, false, "${signature_name} : Error processing arguments");
#end if
#set $arg_list = ", ".join($arg_array)
#if $ret_type.name != "void"
#if $ret_type.is_enum
$ret_type.enum_declare_type result = ($ret_type.enum_declare_type)cobj->${func_name}($arg_list);
#else
${ret_type.get_whole_name($generator)} result = cobj->${func_name}($arg_list);
#end if
${ret_type.from_native({"generator": $generator,
"in_value": "result",
"out_value": "s.rval()",
"class_name": $ret_type.get_class_name($generator),
"ntype": str($ret_type),
"level": 2})};
SE_PRECONDITION2(ok, false, "${signature_name} : Error processing arguments");
#else
cobj->${func_name}($arg_list);
#end if
return true;
}
#set $arg_idx = $arg_idx + 1
#end while
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, $arg_count);
#end if
return false;
}
SE_BIND_FUNC(${signature_name})

View File

@@ -0,0 +1,75 @@
## ===== instance function implementation template - for overloaded functions
static bool ${signature_name}(se::State& s)
{
CC_UNUSED bool ok = true;
${namespaced_class_name}* cobj = (${namespaced_class_name}*)s.nativeThisObject();
SE_PRECONDITION2( cobj, false, "${signature_name} : Invalid Native Object");
const auto& args = s.args();
size_t argc = args.size();
#for func in $implementations
#if len($func.arguments) >= $func.min_args
#set arg_count = len($func.arguments)
#set arg_idx = $func.min_args
#while $arg_idx <= $arg_count
#set arg_list = ""
#set arg_array = []
do {
#if $func.min_args >= 0
if (argc == $arg_idx) {
#set $count = 0
#while $count < $arg_idx
#set $arg = $func.arguments[$count]
#set $arg_type = $arg.to_string($generator)
#if $arg.is_numeric
${arg_type} arg${count} = 0;
#elif $arg.is_pointer
${arg_type} arg${count} = nullptr;
#else
${arg_type} arg${count};
#end if
${arg.to_native({"generator": $generator,
"arg_type": $arg_type,
"in_value": "args[" + str(count) + "]",
"out_value": "arg" + str(count),
"class_name": $class_name,
"level": 3,
"is_static": False,
"is_persistent": $is_persistent,
"ntype": str($arg)})};
#set $arg_array += ["arg"+str(count)]
#set $count = $count + 1
#if $arg_idx > 0 and arg_type != "bool"
if (!ok) { ok = true; break; }
#end if
#end while
#set $arg_list = ", ".join($arg_array)
#end if
#if str($func.ret_type) != "void"
#if $func.ret_type.is_enum
$ret_type.enum_declare_type result = ($ret_type.enum_declare_type)cobj->${func.func_name}($arg_list);
#else
${func.ret_type.get_whole_name($generator)} result = cobj->${func.func_name}($arg_list);
#end if
${func.ret_type.from_native({"generator": $generator,
"in_value": "result",
"out_value": "s.rval()",
"class_name": $func.ret_type.get_class_name($generator),
"ntype": str($func.ret_type),
"level": 2})};
SE_PRECONDITION2(ok, false, "${signature_name} : Error processing arguments");
#else
cobj->${func.func_name}($arg_list);
#end if
return true;
}
} while(false);
#set $arg_idx = $arg_idx + 1
#end while
#end if
#end for
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
return false;
}
SE_BIND_FUNC(${signature_name})

View File

@@ -0,0 +1,66 @@
do {
if (${in_value}.isObject() && ${in_value}.toObject()->isFunction())
{
se::Value jsThis(s.thisObject());
se::Value jsFunc(${in_value});
#if $is_static or $is_persistent
jsFunc.toObject()->root();
#else
jsThis.toObject()->attachObject(jsFunc.toObject());
#end if
auto lambda = [=](${lambda_parameters}) -> ${ret_type.name} {
se::ScriptEngine::getInstance()->clearException();
se::AutoHandleScope hs;
#set arg_count = len($param_types)
#if $arg_count > 0 or $ret_type.name != "void"
CC_UNUSED bool ok = true;
#end if
#if $arg_count > 0
se::ValueArray args;
args.resize($arg_count);
#end if
#set $count = 0
#while $count < $arg_count
#set $arg = $param_types[$count]
#set $arg_type = $arg.to_string($generator)
${arg.from_native({"generator": $generator,
"arg_type": $arg_type,
"in_value": "larg" + str(count),
"out_value": "args[" + str(count) + "]",
"class_name": $class_name,
"level": 2,
"ntype": str($arg)})};
#set $count = $count + 1
#end while
se::Value rval;
se::Object* thisObj = jsThis.isObject() ? jsThis.toObject() : nullptr;
se::Object* funcObj = jsFunc.toObject();
#if $arg_count > 0
bool succeed = funcObj->call(args, thisObj, &rval);
#else
bool succeed = funcObj->call(se::EmptyValueArray, thisObj, &rval);
#end if
if (!succeed) {
se::ScriptEngine::getInstance()->clearException();
}
#if $ret_type.name != "void"
#set $ret_type_name = $ret_type.get_whole_name($generator)
$ret_type_name result;
${ret_type.to_native({"generator": $generator,
"arg_type": $ret_type_name,
"in_value": "rval",
"out_value": "result",
"ntype": str($ret_type),
"level": 2})};
SE_PRECONDITION2(ok, result, "lambda function : Error processing return value with type ${ret_type.name}");
return result;
#end if
};
${out_value} = lambda;
}
else
{
${out_value} = nullptr;
}
} while(false)

View File

@@ -0,0 +1,28 @@
bool register_all_${prefix}(se::Object* obj)
{
#if $target_ns
// Get the ns
se::Value nsVal;
if (!obj->getProperty("${target_ns}", &nsVal))
{
se::HandleObject jsobj(se::Object::createPlainObject());
nsVal.setObject(jsobj);
obj->setProperty("${target_ns}", nsVal);
}
se::Object* ns = nsVal.toObject();
#else
// Get the global ns
se::Object* ns = se::ScriptEngine::getInstance()->getGlobalObject();
#end if
#for jsclass in $sorted_classes
#if $in_listed_classes(jsclass)
js_register_${prefix}_${jsclass}(ns);
#end if
#end for
return true;
}
#if $macro_judgement
\#endif //$macro_judgement
#end if

View File

@@ -0,0 +1,4 @@
#if $macro_judgement
\#endif //$macro_judgement
#end if

View File

@@ -0,0 +1,25 @@
\#include "scripting/js-bindings/auto/${out_file}.hpp"
#if $macro_judgement
$macro_judgement
#end if
\#include "scripting/js-bindings/manual/jsb_conversions.hpp"
\#include "scripting/js-bindings/manual/jsb_global.h"
#for header in $headers
#set include_header = os.path.basename(header)
#if $replace_headers.has_key(include_header)
\#include "${replace_headers[include_header]}"
#else
#set relative = os.path.relpath(header, $search_path)
#if not '..' in relative
\#include "${relative.replace(os.path.sep, '/')}"
#else
\#include "${include_header}"
#end if
#end if
#end for
#if $cpp_headers
#for header in $cpp_headers
\#include "${header}"
#end for
#end if

View File

@@ -0,0 +1,12 @@
#pragma once
\#include "base/ccConfig.h"
#if $macro_judgement
$macro_judgement
#end if
\#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
#if $hpp_headers
#for header in $hpp_headers
\#include "${header}"
#end for
#end if

View File

@@ -0,0 +1,3 @@
#set generator = $current_class.generator
se::Object* __jsb_${current_class.underlined_class_name}_proto = nullptr;
se::Class* __jsb_${current_class.underlined_class_name}_class = nullptr;

View File

@@ -0,0 +1,7 @@
#set generator = $current_class.generator
extern se::Object* __jsb_${current_class.underlined_class_name}_proto;
extern se::Class* __jsb_${current_class.underlined_class_name}_class;
bool js_register_${current_class.underlined_class_name}(se::Object* obj);
bool register_all_${generator.prefix}(se::Object* obj);

View File

@@ -0,0 +1,75 @@
## ===== member implementation template
static bool ${signature_name}_get_${name}(se::State& s)
{
${namespaced_class_name}* cobj = (${namespaced_class_name}*)s.nativeThisObject();
SE_PRECONDITION2(cobj, false, "${signature_name}_get_${name} : Invalid Native Object");
CC_UNUSED bool ok = true;
se::Value jsret;
#if $ntype.is_object and not $ntype.object_can_convert($generator, False)
${ntype.from_native({"generator": $generator,
"type_name": $ntype.namespaced_class_name.replace("*", ""),
"ntype": $ntype.get_whole_name($generator),
"level": 2,
"in_value": "cobj->" + $pretty_name,
"out_value": "jsret"
})};
#else
${ntype.from_native({"generator": $generator,
"type_name": $ntype.namespaced_class_name.replace("*", ""),
"ntype": $ntype.get_whole_name($generator),
"level": 2,
"scriptname": $generator.scriptname_from_native($ntype.namespaced_class_name, $ntype.namespace_name),
"in_value":"cobj->" + $pretty_name,
"out_value": "jsret"
})};
#end if
s.rval() = jsret;
return true;
}
SE_BIND_PROP_GET(${signature_name}_get_${name})
static bool ${signature_name}_set_${name}(se::State& s)
{
const auto& args = s.args();
${namespaced_class_name}* cobj = (${namespaced_class_name}*)s.nativeThisObject();
SE_PRECONDITION2(cobj, false, "${signature_name}_set_${name} : Invalid Native Object");
CC_UNUSED bool ok = true;
#set $arg_type = $ntype.to_string($generator)
#if $ntype.is_numeric
$arg_type arg0 = 0;
#elif $ntype.is_pointer
$arg_type arg0 = nullptr;
#else
$arg_type arg0;
#end if
#if $ntype.is_object and not $ntype.object_can_convert($generator)
${ntype.to_native({"generator": $generator,
"arg_idx": 2,
"arg_type": $arg_type,
"ntype": $ntype.get_whole_name($generator),
"in_value": "args[0]",
"out_value": "arg0",
"func_name": $name,
"level": 2,
"arg":$ntype,
})};
#else
${ntype.to_native({"generator": $generator,
"arg_idx": 2,
"arg_type": $arg_type,
"in_value": "args[0]",
"out_value": "arg0",
"func_name": $name,
"scriptname": $generator.scriptname_from_native($ntype.namespaced_class_name, $ntype.namespace_name),
"level": 2,
"arg":$ntype,
})};
#end if
SE_PRECONDITION2(ok, false, "${signature_name}_set_${name} : Error processing new value");
cobj->$pretty_name = arg0;
return true;
}
SE_BIND_PROP_SET(${signature_name}_set_${name})

View File

@@ -0,0 +1,131 @@
#set has_constructor = False
#set generator = $current_class.generator
#set methods = $current_class.methods_clean()
#set st_methods = $current_class.static_methods_clean()
#set public_fields = $current_class.public_fields
#if $current_class.methods.has_key('constructor')
#set has_constructor = True
#set constructor = $current_class.methods.constructor
${current_class.methods.constructor.generate_code($current_class)}
#end if
#if $generator.in_listed_extend_classed($current_class.class_name) and $has_constructor
#if not $constructor.is_overloaded
${constructor.generate_code($current_class, None, False, True)}
#else
${constructor.generate_code($current_class, False, True)}
#end if
#end if
#if len($current_class.parents) > 0
extern se::Object* __jsb_${current_class.parents[0].underlined_class_name}_proto;
#end if
#if not $current_class.is_abstract
static bool js_${current_class.underlined_class_name}_finalize(se::State& s)
{
#if $current_class.rename_destructor is None
CCLOGINFO("jsbindings: finalizing JS object %p (${current_class.namespaced_class_name})", s.nativeThisObject());
#if $current_class.is_ref_class
${current_class.namespaced_class_name}* cobj = (${current_class.namespaced_class_name}*)s.nativeThisObject();
cobj->release();
#else
#if not $current_class.is_class_owned_by_cpp
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
{
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
${current_class.namespaced_class_name}* cobj = (${current_class.namespaced_class_name}*)s.nativeThisObject();
delete cobj;
}
#end if
#end if
#else
// destructor is skipped
#end if
return true;
}
SE_BIND_FINALIZE_FUNC(js_${current_class.underlined_class_name}_finalize)
#end if
#if $current_class.rename_destructor is not None
static bool js_${current_class.underlined_class_name}_${current_class.rename_destructor}(se::State& s)
{
CCLOGINFO("jsbindings: destory JS object %p (${current_class.namespaced_class_name})", s.nativeThisObject());
#if $current_class.is_ref_class
${current_class.namespaced_class_name}* cobj = (${current_class.namespaced_class_name}*)s.nativeThisObject();
cobj->release();
#else
#if not $current_class.is_class_owned_by_cpp
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
if (iter != se::NonRefNativePtrCreatedByCtorMap::end())
{
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
${current_class.namespaced_class_name}* cobj = (${current_class.namespaced_class_name}*)s.nativeThisObject();
delete cobj;
}
#end if
#end if
auto objIter = se::NativePtrToObjectMap::find(s.nativeThisObject());
if(objIter != se::NativePtrToObjectMap::end())
{
objIter->second->clearPrivateData(true);
}
return true;
}
SE_BIND_FUNC(js_${current_class.underlined_class_name}_${current_class.rename_destructor})
#end if
bool js_register_${generator.prefix}_${current_class.class_name}(se::Object* obj)
{
#if has_constructor
#if len($current_class.parents) > 0
auto cls = se::Class::create("${current_class.target_class_name}", obj, __jsb_${current_class.parents[0].underlined_class_name}_proto, _SE(js_${generator.prefix}_${current_class.class_name}_constructor));
#else
auto cls = se::Class::create("${current_class.target_class_name}", obj, nullptr, _SE(js_${generator.prefix}_${current_class.class_name}_constructor));
#end if
#else
#if len($current_class.parents) > 0
auto cls = se::Class::create("${current_class.target_class_name}", obj, __jsb_${current_class.parents[0].underlined_class_name}_proto, nullptr);
#else
auto cls = se::Class::create("${current_class.target_class_name}", obj, nullptr, nullptr);
#end if
#end if
#for m in public_fields
#if $generator.should_bind_field($current_class.class_name, m.name)
cls->defineProperty("${m.name}", _SE(${m.signature_name}_get_${m.name}), _SE(${m.signature_name}_set_${m.name}));
#end if
#end for
#for m in methods
#set fn = m['impl']
cls->defineFunction("${m['name']}", _SE(${fn.signature_name}));
#end for
#if $generator.in_listed_extend_classed($current_class.class_name) and $has_constructor
cls->defineFunction("ctor", _SE(js_${generator.prefix}_${current_class.class_name}_ctor));
#end if
#if $current_class.rename_destructor is not None
cls->defineFunction("${current_class.rename_destructor}", _SE(js_${current_class.underlined_class_name}_${current_class.rename_destructor}));
#end if
#if len(st_methods) > 0
#for m in st_methods
#set fn = m['impl']
cls->defineStaticFunction("${m['name']}", _SE(${fn.signature_name}));
#end for
#end if
#if not $current_class.is_abstract
cls->defineFinalizeFunction(_SE(js_${current_class.underlined_class_name}_finalize));
#end if
cls->install();
JSBClassType::registerClass<${current_class.namespaced_class_name}>(cls);
__jsb_${current_class.underlined_class_name}_proto = cls->getProto();
__jsb_${current_class.underlined_class_name}_class = cls;
#if $generator.in_listed_extend_classed($current_class.class_name) and not $current_class.is_abstract
jsb_set_extend_property("${generator.target_ns}", "${current_class.target_class_name}");
#end if
se::ScriptEngine::getInstance()->clearException();
return true;
}

View File

@@ -0,0 +1,88 @@
## ===== static function implementation template
static bool ${signature_name}(se::State& s)
{
const auto& args = s.args();
size_t argc = args.size();
#if len($arguments) >= $min_args
#set arg_count = len($arguments)
#set arg_idx = $min_args
#if ($arg_count > 0 or str($ret_type) != "void")
CC_UNUSED bool ok = true;
#end if
#while $arg_idx <= $arg_count
if (argc == ${arg_idx}) {
#set arg_list = ""
#set arg_array = []
#set $count = 0
#while $count < $arg_idx
#set $arg = $arguments[$count]
#set $arg_type = $arg.to_string($generator)
#if $arg.is_numeric
$arg_type arg${count} = 0;
#elif $arg.is_pointer
$arg_type arg${count} = nullptr;
#else
$arg_type arg${count};
#end if
#set $count = $count + 1
#end while
#set $count = 0
#while $count < $arg_idx
#set $arg = $arguments[$count]
#set $arg_type = $arg.to_string($generator)
${arg.to_native({"generator": $generator,
"arg_type": $arg_type,
"in_value": "args[" + str(count) + "]",
"out_value": "arg" + str(count),
"class_name": $class_name,
"level": 2,
"is_static": True,
"is_persistent": $is_persistent,
"ntype": str($arg)})};
#set $arg_array += ["arg"+str($count)]
#set $count = $count + 1
#end while
#if $arg_idx > 0
SE_PRECONDITION2(ok, false, "${signature_name} : Error processing arguments");
#end if
#set $arg_list = ", ".join($arg_array)
#if str($ret_type) != "void"
#if $func_name.startswith("create") and $is_ref_class
auto result = ${namespaced_class_name}::${func_name}($arg_list);
result->retain();
auto obj = se::Object::createObjectWithClass(__jsb_${underlined_class_name}_class);
obj->setPrivateData(result);
s.rval().setObject(obj);
#elif $func_name.startswith("getInstance") and $is_ref_class
auto result = ${namespaced_class_name}::${func_name}($arg_list);
se::Value instanceVal;
native_ptr_to_seval<${namespaced_class_name}>(result, __jsb_${underlined_class_name}_class, &instanceVal);
instanceVal.toObject()->root();
s.rval() = instanceVal;
#else
#if $ret_type.is_enum
$ret_type.enum_declare_type result = ($ret_type.enum_declare_type)${namespaced_class_name}::${func_name}($arg_list);
#else
${ret_type.get_whole_name($generator)} result = ${namespaced_class_name}::${func_name}($arg_list);
#end if
${ret_type.from_native({"generator": $generator,
"in_value": "result",
"out_value": "s.rval()",
"class_name": $ret_type.get_class_name($generator),
"ntype": str($ret_type),
"level": 1})};
SE_PRECONDITION2(ok, false, "${signature_name} : Error processing arguments");
#end if
#else
${namespaced_class_name}::${func_name}($arg_list);
#end if
return true;
}
#set $arg_idx = $arg_idx + 1
#end while
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, $arg_count);
#end if
return false;
}
SE_BIND_FUNC(${signature_name})

View File

@@ -0,0 +1,70 @@
## ===== static function implementation template - for overloaded functions
static bool ${signature_name}(se::State& s)
{
CC_UNUSED bool ok = true;
const auto& args = s.args();
size_t argc = args.size();
#for func in $implementations
#if len($func.arguments) >= $func.min_args
#set arg_count = len($func.arguments)
#set arg_idx = $func.min_args
#while $arg_idx <= $arg_count
do {
if (argc == ${arg_idx}) {
#set arg_list = ""
#set arg_array = []
#set count = 0
#while $count < $arg_idx
#set $arg = $func.arguments[$count]
#set $arg_type = $arg.to_string($generator)
#if $arg.is_numeric
$arg_type arg${count} = 0;
#elif $arg.is_pointer
$arg_type arg${count} = nullptr;
#else
$arg_type arg${count};
#end if
${arg.to_native({"generator": $generator,
"arg_type": $arg_type,
"in_value": "args[" + str(count) + "]",
"out_value": "arg" + str(count),
"class_name": $class_name,
"level": 3,
"is_static": True,
"is_persistent": $is_persistent,
"ntype": str($arg)})};
#set $arg_array += ["arg"+str(count)]
#set $count = $count + 1
#if $arg_idx > 0
if (!ok) { ok = true; break; }
#end if
#end while
#set $arg_list = ", ".join($arg_array)
#if str($func.ret_type) != "void"
#if $func.ret_type.is_enum
$ret_type.enum_declare_type result = ($ret_type.enum_declare_type)${namespaced_class_name}::${func.func_name}($arg_list);
#else
${func.ret_type.get_whole_name($generator)} result = ${namespaced_class_name}::${func.func_name}($arg_list);
#end if
${func.ret_type.from_native({"generator": $generator,
"in_value": "result",
"out_value": "s.rval()",
"class_name": $func.ret_type.get_class_name($generator),
"ntype": str($func.ret_type),
"level": 3})};
SE_PRECONDITION2(ok, false, "${signature_name} : Error processing arguments");
#else
${namespaced_class_name}::${func.func_name}($arg_list);
#end if
return true;
}
#set $arg_idx = $arg_idx + 1
} while (false);
#end while
#end if
#end for
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
return false;
}
SE_BIND_FUNC(${signature_name})