Harmless Programmer

Just one more programming blog.

Extending Cocos2d JS Bindings. Part 1: Automatic Bindings

Since version 2.1 cocos2d-iphone comes with ability to write code in JavaScript. This allows you to write your code once and then reuse the code with cocos2d-x or cococs2d-html5. All cocos2d nodes, CocosDension, CocosBuilder reader and Chipmunk are supported. But what about third parties? Do we need to rewrite other great libraries in JS to use them? No. And here jsbindings project comes for the rescue.

While official documentation is pretty good to get started, there are few pitfalls when using this tool in real project. So, lets explore the process of binding generation step by step and allow JS coders to use CCScrollView. At this tutorial we’ll explore automatic binding process and bind most of the CCScrollView methods to JS, next time we’ll focus on manual bindings and complete the rest.

Esprima Tutorial

Recently I had a task that sounded something like this:

Get a JS code and generate some other JS code from it.

The first part was most difficult. Info we need from code was too complex to get using regular expressions. So the search for JS parser began. It ended pretty soon when I found Esprima parser. Now I want to share my experience with it in a form of tutorial. We won’t be building code generator - I think simpler task will be enough to dive in.

Intro

Hi everyone! This is my first blog post. Who am I? I’m a software engineer at BeKitzur (site under construction at the moment). I work on various projects, mostly mobile apps. I code in Objective-C, Java, JS (browsers and node.js). I also make short video games occasionally, but this is more hobby than a professional activity. Here is two games which I made in collaboration with a few great people for ludum dare competition:

So the blog will mostly about it - mobile development, javascript, node and simple game development. I don’t expect to post frequently - I rarely have an idea for a good technical article. But hope you find something useful here anyway.