Add support for a type

I’m looking into adding CCControlButtons into my project, but I’m running into a problem where I’m unable to set a target on it for a particular event. It looks like cxx-generator doesn’t support SEL_CCControlHandler, so it bails when it runs into that argument.

I’m reading through the code now to try to tease out how to add support for this type, but are there any good examples of how to add support for a new type?

Yes, cxx-generator couldn’t bind function pointer. You should bind it by yourself.
You could refers to `jsb_cocos2dx_extension_manual.cpp` if you are using the latest release.

BTW, we have renamed `cxx-generator` to `bindings-generator`. And the URL of this submodule is at https://github.com/cocos2d/bindings-generator.

Got it. I’ll take a stab at adding support for CCControlButton and send a pull request upstream when I get it working.

Is there a recommended approach to updating my Xcode project to use cocos2d-x that’s been checked out from git? I’m currently using the template generated by cocos2d-2.1rc0-x-2.1.2.

Maybe you should get the latest codes on github, re-install the template, and create a new jsb project, copy the sources to where you want to replace.
That will be great if you could send a Pull Request to us. Thanks.

I’ll give that a swing and see if I can get it to play nicely. I had previously tried copying things over by hand, and it was a nightmare of a process :confused:

I’ve got something working, but thought I’d get some feedback on my approach before I commit the changes and send a pull request. I have a few questions:

  1. I modeled my approach after CCEditBox, which uses JSB_EditBoxDelegate. I see that a JSB_EditBoxDelegate is allocated in js_cocos2dx_CCEditBox_setDelegate, but I don’t see where it’s freed. Can you point me to this?
  2. It looks like there’s no support for taking a JS function object and calling it directly. Is this true? It seems a little odd to have JS pass in strings as callback method names, but I guess that works (and it’s what I’ve done in previous cases when I’ve bound methods manually).
  3. What’s the current coding standard? I’d like to follow the convention as much as possible, but I’ve noticed a few distinct styles in the codebase and I’m not sure which one’s the best one to follow.

Is this the correct approach? If it sounds generally sound, I’ll send a pull request along. Feedback would be much appreciated. Thanks!

  1. I modeled my approach after CCEditBox, which uses JSB_EditBoxDelegate. I see that a JSB_EditBoxDelegate is allocated in js_cocos2dx_CCEditBox_setDelegate, but I don’t see where it’s freed. Can you point me to this?

Yes, some delegate instances are never released after being created. For this, I don’t have a good way to avoid. But I think it’s not so important since every time a CCEditBox is created and delegate is set, it just wastes 8 byte memory. In normal games, we will not create CCEditBox frequently, right? If you find a better way, feel free to let me know, thanks.

  1. It looks like there’s no support for taking a JS function object and calling it directly. Is this true? It seems a little odd to have JS pass in strings as callback method names, but I guess that works (and it’s what I’ve done in previous cases when I’ve bound methods manually).

We did support this function, please refer to ScriptingCore::executeFunctionWithOwner, if you want to invoke global function in JS, the first parameter should be OBJECT_TO_JSVAL->getGlobalObject).

  1. What’s the current coding standard? I’d like to follow the convention as much as possible, but I’ve noticed a few distinct styles in the codebase and I’m not sure which one’s the best one to follow.

Yes, it seems that we should format the code style, you could refer to wiki page about the convention(http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Cocos_Coding_Style).

Sorry for the late reply. We’ve been using this in my company’s code base now for a month or so, and it’s been working out well. I’ve submitted a pull request, so hopefully this is something others will be able to use as well.

Thanks, I’ll check it.