The last time Hackerfall tried to access this page, it returned a not found error. A cached version of the page is below, or clickhereto continue anyway

GitHub - jerrymarino/cupertinojs: Cupertino.js - Compile Javascript to Cocoa

Cupertino.js - Compile Javascript to Cocoa

Cupertino.js is a implementation of the Javascript programming language designed with Cocoa support as a primary consideration. It includes a static compiler and uber dynamic runtime that sits atop of the Objective-C runtime.

It exposes a simple interface to Objective-C: Javascript code is statically compiled to Objective-C. Objects and functions are derived from NSObject, strings are NSStrings, numbers are NSNumbers, and message dispatch uses objc_msgSend.

Declare variables

Perform arithmetic

Loop

for (var i = 99; i > 0; i--){
    console.log(i, " bottles of beer on the wall.") 
}

Objects

var tallBoy = {"label" : "Pabst", "size" : 24.0}

Define functions, methods, and properties

function Todo(){
    this.message = null

    this.log = function(){
        console.log(this.message)
    }
}

Instantiate functions

var beers = new Todo();
beers.message = "Drink some beers"

Call functions

Call Objective-C methods

var bottlesOnTheWall = NSString.stringWithFormat("%@ of beer on the wall", 99)
bottlesOnTheWall.lowercaseString()

//short hand
bottlesOnTheWall.lowercaseString

Message send struct

//Structs are casted from c structs to Javascript objects
//cast functions take the struct as argument and are named after the type or typedef
var applicationFrame = CGRect(UIScreen.mainScreen.applicationFrame)

console.log("screen height ", applicationFrame.size.height)

Mutate structs

applicationFrame.origin.y = 10

Pass structs back to Objective-C types

var window = UIWindow.alloc.init
window.frame = applicationFrame

Define class properties

Full support for 'this'

this.fruits = ["apples", "banannas", "oranges"]

Subclass Objective-C classes

var TodoListController = UIViewController.extend("TodoListController")

Prototype instance methods

TodoListViewController.prototype.numberOfSectionsInTableView = function(tableView){
    return ObjCInt(1)
}

Bind function objects as methods

// Define function AppDelegate
function AppDelegate(){}

function DidLaunch(application, options){
    console.log("Launched! ", this)
}

// Implement  -[AppDelegate application:didFinishLaunchingWithOptions:]
// with the body of DidLaunch
//
// 'this' is an instance of AppDelegate
AppDelegate.prototype.applicationDidFinishLaunchingWithOptions = DidLaunch

Import Objective-C

//Use the objc_import macro to import objective-c headers
objc_import("TDNetworkRequest.h")

// Interfaces are exported to the global namespace
var request = TDNetworkRequest.get("latest-todos")
reqest.send()

Examples

The examples directory contains a iPhone app that runs in the simulator and comes complete with a UITableView implementation.

State of union:

Although the example app builds and runs in the simulator, Cupertino.js is not yet production ready.

There several features not yet implemented including:

Checkout the 0.1 Beta roadmap here

Project setup

Cupertino.js has the following dependencies:

The install script will set up the development environment

./bootstrap.sh

Installing the compiler

Run the scheme cujs in release configuration

The compiler cujs will be installed to /usr/local/bin

Running the example "Todoie"

Once the compiler is installed, the example should run in the simulator.

For more check the Wiki

Continue reading on github.com