mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2025-10-09 17:55:28 +00:00
初始化
This commit is contained in:
@@ -0,0 +1 @@
|
||||
};
|
@@ -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
|
||||
|
@@ -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
|
||||
},
|
||||
|
@@ -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
|
||||
},
|
||||
|
@@ -0,0 +1,12 @@
|
||||
#if $target_ns
|
||||
#if $prefix
|
||||
/**
|
||||
* @module ${prefix}
|
||||
*/
|
||||
#else
|
||||
/**
|
||||
* @module ${target_ns}
|
||||
*/
|
||||
#end if
|
||||
var ${target_ns} = ${target_ns} || {};
|
||||
#end if
|
@@ -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)
|
@@ -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)
|
@@ -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)
|
@@ -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)
|
@@ -0,0 +1 @@
|
||||
SE_DECLARE_FUNC(js_${generator.prefix}_${class_name}_${func_name});
|
@@ -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})
|
@@ -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})
|
@@ -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)
|
@@ -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
|
@@ -0,0 +1,4 @@
|
||||
|
||||
#if $macro_judgement
|
||||
\#endif //$macro_judgement
|
||||
#end if
|
@@ -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
|
||||
|
@@ -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
|
@@ -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;
|
@@ -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);
|
@@ -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})
|
@@ -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;
|
||||
}
|
||||
|
@@ -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})
|
@@ -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})
|
Reference in New Issue
Block a user