Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support interfaces as callbacks from C++ (in addition to std::function support) #2

Open
mathiasi opened this issue Sep 12, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@mathiasi
Copy link

First for all: very interesting project! I was testing it for a new project but I need the ability to implement a C++ interface in the "client" languages.
I could see from https://github.com/scapix-com/example1/blob/a0a0b5a27e4c68c1e2f6bb210901206ff378b213/source/chat/contact.h there is some traces of something along those lines (scapix::bridge::interface). What is the current status of this? Was it scratched or is it coming in the pipelines?

@Boris-Rasin
Copy link
Member

Thanks!
Implementing interfaces is definitely in the pipeline, but right now you can use already supported std::function<> parameters to implement callbacks to client languages.

@mathiasi
Copy link
Author

Good to hear! Yea I found the way to do callbacks but that doesn't fully meet my needs. I need entire interfaces to be implemented in the client language and have it passed to C++.
I'll keep an eye out for updates :)

@Boris-Rasin Boris-Rasin added the enhancement New feature or request label Sep 19, 2019
@dmalukov
Copy link

dmalukov commented Dec 3, 2019

@Boris-Rasin do I understand correctly that using c++ interfaces in client languages is impossible now?

For instance, I have an interface Foo, it's implementation and the factory Bar that produces Foo.
I get a SIGABRT on creating Foo object in JNI.

Bar.h

#include <memory>

#include <scapix/bridge/object.h>
#include "Foo.h"

class Bar : public scapix::bridge::object<Bar> {
public:
    std::shared_ptr<Foo> getFoo() {
        return std::static_pointer_cast<Foo>(std::make_shared<FooImpl>());
    }
};

Foo.h

#include <scapix/bridge/object.h>

class Foo : public scapix::bridge::object<Foo> {
public:
    virtual ~Foo() = default;
    virtual void baz() = 0;
};

class FooImpl : public Foo {
public:
    void baz() override {}
};

client's code

val bar = Bar()
val foo = bar.getFoo()   //  SIGABRT here
foo.baz()

@Boris-Rasin
Copy link
Member

Boris-Rasin commented Dec 4, 2019

dmalukov, this issue is about support for interfaces as callbacks from C++ (in addition to std::function support). Your example is supposed to work. I will take a look. Can you open a different issue for it?

@Boris-Rasin Boris-Rasin changed the title Interface support? Support interfaces as callbacks from C++ (in addition to std::function support) Dec 4, 2019
@Boris-Rasin
Copy link
Member

Interfaces as callbacks from C++ (overriding C++ virtual functions in bridged languages) are supported in the latest version of Scapix, currently for Python bridge only.

Support for other languages coming soon, stay tuned!

@Boris-Rasin
Copy link
Member

Added support for overriding C++ virtual functions in JavaScript bridge (now supported in Python and JavaScript bridges).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants