Fixing CallFuncN bindings to properly pass optional third parameter

This commit is contained in:
Rohan Kuruvilla 2012-10-24 14:05:29 -07:00 committed by James Chen
parent 094d52664d
commit 5760ea305c
3 changed files with 57 additions and 55 deletions

View File

@ -48,7 +48,11 @@ var Bullet = cc.Sprite.extend({
cc.ArrayRemoveObject(MW.CONTAINER.ENEMY_BULLETS,this);
cc.ArrayRemoveObject(MW.CONTAINER.PLAYER_BULLETS,this);
this.removeFromParentAndCleanup(true);
var removeExplode = cc.CallFunc.create(explode,explode.removeFromParentAndCleanup);
var removeExplode = cc.CallFunc.create(explode, function(sender) {
explode.removeFromParentAndCleanup(true);
});
explode.runAction(cc.ScaleBy.create(0.3, 2,2));
explode.runAction(cc.Sequence.create(cc.FadeOut.create(0.3), removeExplode));
},

View File

@ -554,8 +554,7 @@ void JSCallFunc::setJSCallbackThis(jsval thisObj) {
}
void JSCallFunc::setExtraDataField(jsval data) {
extraData = new jsval();
*extraData = data;
extraData = data;
}
void JSCallFunc::setTargetForNativeNode(CCNode *pNode, JSCallFunc *target) {
@ -1400,63 +1399,63 @@ extern JSObject* js_cocos2dx_CCCardinalSplineBy_prototype;
extern JSObject* js_cocos2dx_CCBezierTo_prototype;
extern JSObject* js_cocos2dx_CCBezierBy_prototype;
// setBlendFunc
template<class T>
JSBool js_cocos2dx_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSObject *obj;
T* cobj;
obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cobj = (T*)(proxy ? proxy->ptr : NULL);
TEST_NATIVE_OBJECT(cx, cobj)
// setBlendFunc
template<class T>
JSBool js_cocos2dx_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSObject *obj;
T* cobj;
obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cobj = (T*)(proxy ? proxy->ptr : NULL);
TEST_NATIVE_OBJECT(cx, cobj)
if (argc == 2)
{
GLenum src, dst;
JS_ValueToInt32(cx, argv[0], (int32_t*)&src);
{
GLenum src, dst;
JS_ValueToInt32(cx, argv[0], (int32_t*)&src);
JS_ValueToInt32(cx, argv[1], (int32_t*)&dst);
ccBlendFunc blendFunc = {src, dst};
cobj->setBlendFunc(blendFunc);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2);
return JS_FALSE;
}
JSBool js_cocos2dx_CCSprite_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
{
return js_cocos2dx_setBlendFunc<CCSprite>(cx, argc, vp);
}
JSBool js_cocos2dx_CCSpriteBatchNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
{
return js_cocos2dx_setBlendFunc<CCSpriteBatchNode>(cx, argc, vp);
}
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2);
return JS_FALSE;
}
JSBool js_cocos2dx_CCSprite_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
{
return js_cocos2dx_setBlendFunc<CCSprite>(cx, argc, vp);
}
JSBool js_cocos2dx_CCSpriteBatchNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
{
return js_cocos2dx_setBlendFunc<CCSpriteBatchNode>(cx, argc, vp);
}
// JSBool js_cocos2dx_CCMotionStreak_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
// {
// return js_cocos2dx_setBlendFunc<CCMotionStreak>(cx, argc, vp);
// }
JSBool js_cocos2dx_CCAtlasNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
{
return js_cocos2dx_setBlendFunc<CCAtlasNode>(cx, argc, vp);
}
JSBool js_cocos2dx_CCParticleBatchNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
{
return js_cocos2dx_setBlendFunc<CCParticleBatchNode>(cx, argc, vp);
}
JSBool js_cocos2dx_CCLayerColor_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
{
return js_cocos2dx_setBlendFunc<CCLayerColor>(cx, argc, vp);
JSBool js_cocos2dx_CCAtlasNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
{
return js_cocos2dx_setBlendFunc<CCAtlasNode>(cx, argc, vp);
}
JSBool js_cocos2dx_CCParticleSystem_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
{
return js_cocos2dx_setBlendFunc<CCParticleSystem>(cx, argc, vp);
JSBool js_cocos2dx_CCParticleBatchNode_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
{
return js_cocos2dx_setBlendFunc<CCParticleBatchNode>(cx, argc, vp);
}
JSBool js_cocos2dx_CCLayerColor_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
{
return js_cocos2dx_setBlendFunc<CCLayerColor>(cx, argc, vp);
}
JSBool js_cocos2dx_CCParticleSystem_setBlendFunc(JSContext *cx, uint32_t argc, jsval *vp)
{
return js_cocos2dx_setBlendFunc<CCParticleSystem>(cx, argc, vp);
}
void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global)

View File

@ -82,7 +82,7 @@ void register_cocos2dx_js_extensions(JSContext* cx, JSObject* obj);
class JSCallFunc: public CCObject {
public:
JSCallFunc(jsval func): jsCallback(func) {}
JSCallFunc() { extraData = NULL; }
JSCallFunc() {}
virtual ~JSCallFunc() {
return;
}
@ -102,16 +102,15 @@ public:
js_proxy_t *proxy = js_get_or_create_proxy<cocos2d::CCNode>(cx, node);
valArr[0] = OBJECT_TO_JSVAL(proxy->obj);
if(extraData != NULL) {
valArr[1] = *extraData;
if(!JSVAL_IS_NULL(extraData)) {
valArr[1] = extraData;
} else {
valArr[1] = JSVAL_NULL;
}
jsval retval;
if(jsCallback != JSVAL_VOID || jsThisObj != JSVAL_VOID) {
JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(jsThisObj), jsCallback, 1, valArr, &retval);
JS_CallFunctionValue(cx, JSVAL_TO_OBJECT(jsThisObj), jsCallback, 2, valArr, &retval);
}
JSCallFunc::setTargetForNativeNode(node, (JSCallFunc *)this);
@ -119,7 +118,7 @@ public:
private:
jsval jsCallback;
jsval jsThisObj;
jsval *extraData;
jsval extraData;
};