Introduction

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

#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);

    void notify(std::function<bool(std::shared_ptr<contact>)> callback);
};

List your C++ header in CMake

Every time this header changes, Scapix will automatically regenerate bindings during build. This works in any IDE supported by CMake: Visual Studio, XCode, Android Studio, etc.

find_package(Scapix REQUIRED)

scapix_bridge_headers(
    #...
    "source/chat/contact.h"
)

Call your C++ code from other languages

class View {
    private Contact contact = new Contact();

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

        contact.notify((Contact c) -> {
            //...
            return true;
        });
    }
}
@implementation ViewController

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

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

    [contact notify:^ (Contact* c) {
        //...
        return TRUE;
    }];
}

@end
class ViewController: UIViewController {
    func send(friend: Contact) {
        let contact = Contact()

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

        contact.notify() {
            (c: Contact) in
            //...
            return true
        }
    }
}
import chatlib

def callback(c):
    #...
    return True

def send():
    friend = chatlib.Contact()
    contact = chatlib.Contact()
    contact.sendMessage("Hello", friend)
    contact.addTags(["a","b","c"])
    contact.addFriends([friend])
    contact.notify(callback)
<script>
var Module = {
    onRuntimeInitialized: function() {
        var friend = new Module.Contact();
        var contact = new Module.Contact();

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

        contact.notify(function(c)
        {
            //...
            return true;
        });
    }
};
</script>
public class Test {
    public void send(Contact friend) {
        Contact contact = new Contact();

        contact.sendMessage("Hello", friend);
        contact.addTags(new string[] {"a","b","c"});
        contact.addFriends(new Contact[] {friend});

        contact.notify((Contact c) => {
            //...
            return true;
        });
    }
}

See list of bridged types