-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from pandamicro/v3
Add auto bindings for public members
- Loading branch information
Showing
6 changed files
with
250 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
## ===== member implementation template | ||
int ${signature_name}_get${name}(lua_State* tolua_S) | ||
{ | ||
${namespaced_class_name}* cobj = nullptr; | ||
\#if COCOS2D_DEBUG >= 1 | ||
tolua_Error tolua_err; | ||
if (!tolua_isusertype(tolua_S,1,"${generator.scriptname_from_native($namespaced_class_name, $namespace_name)}",0,&tolua_err)) goto tolua_lerror; | ||
\#endif | ||
|
||
cobj = (${namespaced_class_name}*)tolua_tousertype(tolua_S,1,0); | ||
|
||
\#if COCOS2D_DEBUG >= 1 | ||
if (!cobj) | ||
{ | ||
tolua_error(tolua_S,"invalid 'cobj' in function '${signature_name}_get${name}'", nullptr); | ||
return 0; | ||
} | ||
\#endif | ||
|
||
#if $ntype.is_object and not $ntype.object_can_convert($generator, False) | ||
${ntype.from_native({"generator": $generator, | ||
"type_name": $ntype.namespaced_name.replace("*", ""), | ||
"ntype": $ntype.get_whole_name($generator)+"*", | ||
"level": 2, | ||
"scriptname": $generator.scriptname_from_native($ntype.namespaced_name, $ntype.namespace_name), | ||
"in_value":"&cobj->" + $pretty_name, | ||
})}; | ||
#else | ||
${ntype.from_native({"generator": $generator, | ||
"type_name": $ntype.namespaced_name.replace("*", ""), | ||
"ntype": $ntype.get_whole_name($generator), | ||
"level": 2, | ||
"scriptname": $generator.scriptname_from_native($ntype.namespaced_name, $ntype.namespace_name), | ||
"in_value":"cobj->" + $pretty_name, | ||
})}; | ||
#end if | ||
|
||
return 1; | ||
\#if COCOS2D_DEBUG >= 1 | ||
tolua_lerror: | ||
tolua_error(tolua_S,"#ferror in function '${signature_name}_get${name}'.",&tolua_err); | ||
return 0; | ||
\#endif | ||
} | ||
|
||
int ${signature_name}_set${name}(lua_State* tolua_S) | ||
{ | ||
int argc = 0; | ||
${namespaced_class_name}* cobj = nullptr; | ||
bool ok = true; | ||
|
||
\#if COCOS2D_DEBUG >= 1 | ||
tolua_Error tolua_err; | ||
if (!tolua_isusertype(tolua_S,1,"${generator.scriptname_from_native($namespaced_class_name, $namespace_name)}",0,&tolua_err)) goto tolua_lerror; | ||
\#endif | ||
|
||
cobj = (${namespaced_class_name}*)tolua_tousertype(tolua_S,1,0); | ||
|
||
\#if COCOS2D_DEBUG >= 1 | ||
if (!cobj) | ||
{ | ||
tolua_error(tolua_S,"invalid 'cobj' in function '${signature_name}_set${name}'", nullptr); | ||
return 0; | ||
} | ||
\#endif | ||
argc = lua_gettop(tolua_S) - 1; | ||
|
||
if (1 == argc) | ||
{ | ||
#if $ntype.is_object and not $ntype.object_can_convert($generator) | ||
${ntype.to_string($generator)}* arg0 = nullptr; | ||
#else | ||
${ntype.to_string($generator)} arg0; | ||
#end if | ||
${ntype.to_native({"generator": $generator, | ||
"arg_idx": 2, | ||
"out_value": "arg0", | ||
"lua_namespaced_class_name": $generator.scriptname_from_native($namespaced_class_name, $namespace_name), | ||
"func_name": $name, | ||
"scriptname": $generator.scriptname_from_native($ntype.namespaced_name, $ntype.namespace_name), | ||
"level": 2, | ||
"arg":$ntype, | ||
})}; | ||
#if $ntype.is_object and not $ntype.object_can_convert($generator) | ||
cobj->$pretty_name = *arg0; | ||
#else | ||
cobj->$pretty_name = arg0; | ||
#end if | ||
return 0; | ||
} | ||
|
||
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "${generator.scriptname_from_native($namespaced_class_name, $namespace_name)}:${name}",argc, 1); | ||
return 0; | ||
|
||
\#if COCOS2D_DEBUG >= 1 | ||
tolua_lerror: | ||
tolua_error(tolua_S,"#ferror in function '${signature_name}_get${name}'.",&tolua_err); | ||
return 0; | ||
\#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
## ===== member implementation template | ||
bool ${signature_name}_get_${name}(JSContext *cx, uint32_t argc, jsval *vp) | ||
{ | ||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | ||
js_proxy_t *proxy = jsb_get_js_proxy(args.thisv().toObjectOrNull()); | ||
${namespaced_class_name}* cobj = (${namespaced_class_name} *)(proxy ? proxy->ptr : NULL); | ||
JSB_PRECONDITION2( cobj, cx, false, "${signature_name}_get_${name} : Invalid Native Object"); | ||
|
||
#if $ntype.is_object and not $ntype.object_can_convert($generator, False) | ||
${ntype.from_native({"generator": $generator, | ||
"type_name": $ntype.namespaced_name.replace("*", ""), | ||
"ntype": $ntype.get_whole_name($generator)+"*", | ||
"level": 2, | ||
"scriptname": $generator.scriptname_from_native($ntype.namespaced_name, $ntype.namespace_name), | ||
"in_value": "&cobj->" + $pretty_name, | ||
"out_value": "jsval jsret" | ||
})}; | ||
#else | ||
${ntype.from_native({"generator": $generator, | ||
"type_name": $ntype.namespaced_name.replace("*", ""), | ||
"ntype": $ntype.get_whole_name($generator), | ||
"level": 2, | ||
"scriptname": $generator.scriptname_from_native($ntype.namespaced_name, $ntype.namespace_name), | ||
"in_value":"cobj->" + $pretty_name, | ||
"out_value": "jsval jsret" | ||
})}; | ||
#end if | ||
args.rval().set(jsret); | ||
return true; | ||
} | ||
bool ${signature_name}_set_${name}(JSContext *cx, uint32_t argc, jsval *vp) | ||
{ | ||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | ||
js_proxy_t *proxy = jsb_get_js_proxy(args.thisv().toObjectOrNull()); | ||
${namespaced_class_name}* cobj = (${namespaced_class_name} *)(proxy ? proxy->ptr : NULL); | ||
JSB_PRECONDITION2( cobj, cx, false, "${signature_name}_set_${name} : Invalid Native Object"); | ||
|
||
bool ok = true; | ||
#if $ntype.is_object and not $ntype.object_can_convert($generator) | ||
${ntype.to_string($generator)}* arg0 = nullptr; | ||
#else | ||
${ntype.to_string($generator)} arg0; | ||
#end if | ||
${ntype.to_native({"generator": $generator, | ||
"arg_idx": 2, | ||
"in_value": "args.get(0)", | ||
"out_value": "arg0", | ||
"func_name": $name, | ||
"scriptname": $generator.scriptname_from_native($ntype.namespaced_name, $ntype.namespace_name), | ||
"level": 2, | ||
"arg":$ntype, | ||
})}; | ||
JSB_PRECONDITION2(ok, cx, false, "${signature_name}_set_${name} : Error processing new value"); | ||
#if $ntype.is_object and not $ntype.object_can_convert($generator) | ||
cobj->$pretty_name = *arg0; | ||
#else | ||
cobj->$pretty_name = arg0; | ||
#end if | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters