初始化

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,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})