Question

I want to ask that how the code conversion from one programming language to another programming language happens. Like in unity 3d, we write code in c# or js then it can export this to xcode project or android project etc: 1) How can I create the Xcode project like this?

How this conversion takes place: 2) Do they use some bridge for this, How to make this bridge, is this bridge development like a compiler development?

My initial understanding is that bridge should investigate the Cross platform language (like js) and then it converts it to native language. Is there any storage table where it stores this conversion information?

Was it helpful?

Solution

On each platform you would create a library, framework etc. that would parse the javascript (or other language) into the native language.

e.g.

if javascript object == TI.UI.TextField

then create UITextField on iOS

and so on, but much more complicated than this. I've used Titanium before and have seen the generated project contains a Titanium library of some kind.

You would then create some sort of template project that would take in files and run some processing over it and construct the layout.

Then you use command line tools to invoke the build process that would create the app

Edit

Re your comment:

  1. As I mentioned above, in order to create an xcode project like this would require using the command line tools (e.g. Xcode command line docs). You would create a project inside a build folder (like all of the tools you've looked at do), then you would use command line to copy the native library you've made, then copy over the, lets say js, resources that will be compiled / interpreted.

  2. I've already covered this, for each platform, you would need to develop a native library that would enable you to translate JS objects into Objective-c objects (Similar for Android). Each tool can do this a different way, phonegap creates an application with a webview and drops html, css and javascript into it while giving the ability to use some native API's. Titanium does it quite different where the JS is nearly mapped directly to Objective-c. They claim to scan the JS code in order to find what api's / frameworks are being used and include those into the project. Here is a description I found on stackoverflow: How Does Appcelerator Titanium Mobile Work?

  3. I'm unsure as to what your actually asking here, but at some point there is processing to interpret what objective-c object this JS object maps too. So at some point there will be a map of each object type. This is fairly common sense, if in titanium you write var textfield = TI.UI.textfield(...); at some point it needs to know to map that to a [[UITextField alloc] init];. How this mapping is stored? this could be done in hundreds of different ways and how titanium does it exactly I don't know.

I didn't build Titanium, so I can't tell you exactly what each line does. Your question was "How does it do it" and at a high level this is what it does, each language needs a native library to interpret the JS files. If you are trying to create your own tool for doing this, I wouldn't think the place to start is by copying one that already exists. They all function quite differently and leverage knowledge of how all the underlying systems work and how best to exploit this.

If this isn't sufficient for you, you will need to do research or contact a developer for one of these companies and ask them directly but I don't think they will tell you how to reproduce their product. Stackoverflow is not for recommending tools, doing your research for you or discussing best practises, as all of these things lead to personal opinions and preferred development patterns / techniques and are difficult to give a complete answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top