Introduction

1. Derive your C++ class from scapix::bridge::object

#include <scapix/bridge/object.h>

class contact : public scapix::bridge::object<contact>
{
};

2. Add or change any public function

#include <scapix/bridge/object.h>

class contact : public scapix::bridge::object<contact>
{
public:
    std::string name();
    void send_message(const std::string& msg, std::shared_ptr<contact> from);
    void add_tags(const std::vector<std::string>& tags);
    void add_friends(std::vector<std::shared_ptr<contact>> friends);
};

3. Press ‘Build’ in whatever IDE you are using

Scapix automatically generates bindings as part of the build. See example of generated bindings.

4. Call new functions from UI code

Java

class View {
    private contact = new Contact;

    public void send(Contact friend) {
        contact.sendMessage("Hello", friend);
        contact.addTags({"a","b","c"});
        contact.addFriends({friend});
    }
}

Objective C

@implementation ViewController

-(void) send:(Contact*)friend {
    Contact* c = [Contact new];

    [c sendMessage:@"hello", friend];
    [s addTags:@["a","b","c"]];
    [s addFriends:@[friend]];
}

@end

Swift

class ViewController: UIViewController {
    func send(friend: Contact) {
        let c = Contact()

        c.sendMessage("Hello", friend)
        c.addTags(["a","b","c"])
        c.addFriends([friend])
    }
}

JavaScript

<script>
var Module = {
    onRuntimeInitialized: function() {
        var friend = new Module.Contact();
        var c = new Module.Contact();

        c.sendMessage("Hello", friend);
        c.addTags(["a","b","c"]);
        c.addFriends([friend]);
    }
};
</script>

5. Callbacks supported too

#include <scapix/bridge/object.h>

class contact : public scapix::bridge::object<contact>
{
public:
    void notify(std::function<bool(std::shared_ptr<contact>)>);
};

Java

class View
{
    public void send(Contact friend) {
        friend.notify((Contact c) -> {
            //...
            return true;
        });
    }
}

Objective C

@implementation ViewController

-(void) send:(Contact*)friend {
    [friend notify:^ (Contact* c) {
        //...
        return TRUE;
    }];
}

@end

Swift

class ViewController: UIViewController {
    func send(friend: Contact) {
        friend.notify() {
            (c: Contact) in
            //...
            return true
        }
    }
}

JavaScript

<script>
var Module = {
    onRuntimeInitialized: function() {
        var c = new Module.Contact();

        c.notify(function(friend)
        {
            //...
            return true;
        });
    }
};
</script>

See also: automatically bridged types