Hey all,

I've recently worked on some code allowing direct access to class fields and non-virtual class members in C++, and was wondering if anyone else would find it useful? If so, would it be worth making a pull request for phobos? Should that be the case, where should it go?

Example usage (requires https://github.com/D-Programming-Language/dmd/pull/131 ):
----
// someFile.cpp
class A
{
    int someInt;
    void* ptr;
    void myFunc(){}
    int add(int a, int b)
    {
        return a + b;
    }
    virtual void someVirtFunc();
}

// someFile.d
extern(C++)
interface A
{
    mixin CppFields!(A,
        int, "someInt",
        void*, "ptr"
    );
    mixin CppMembers!(A,
        "myFunc", void,
        "add", int, int, int
    );
    void someVirtFunc();
    final void myDMethod()
    {
        myFunc();
        someVirtFunc();
        writefln("someInt: %s; ptr: %s; 1 + 1: %s", someInt,
                                                    ptr,
                                                    add(1, 1)));
    }
}
mixin(A.cppMethods);
----

I also have plans to add support for constructors/destructors if I get chance/it's not too difficult.

--
Robert
http://octarineparrot.com/

Reply via email to