scapix-com / scapix

Scapix Language Bridge
https://www.scapix.com
Other
336 stars 25 forks source link

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

Open mathiasi opened 5 years ago

mathiasi commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 :)

dmalukov commented 4 years ago

@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 commented 4 years ago

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 commented 2 years ago

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 commented 2 years ago

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