June 03, 2021

This is where ImportC should shine, we'd no longer have to maintain bindings manually (hopefully)

June 04, 2021
On 04/06/2021 10:18 AM, russhy wrote:
> This is where ImportC should shine, we'd no longer have to maintain bindings manually (hopefully)

That only includes static linking (both objects and shared libraries).

Dynamic linking of shared libraries which BindBC has as one of its key features isn't covered as of right now (not expected to).

June 04, 2021
On Friday, 4 June 2021 at 00:52:21 UTC, rikki cattermole wrote:
> That only includes static linking (both objects and shared libraries).

Well, if importc works as well as claimed, it would be trivial to do a dynamic load off it using the same pattern I did in simpledisplay's dynamic loader: reflect over the static stuff and mix in dynamic stuff from it.


June 04, 2021

On Thursday, 3 June 2021 at 11:42:05 UTC, Ola Fosheim Grøstad wrote:

>

On Thursday, 3 June 2021 at 11:35:32 UTC, evilrat wrote:

>

Unfortunately it is still sucks because it uses STL, and there is tons of junk in it. Maybe if I could just strip produced garbage and take only what is used (atomics, unique_ptr, strings, etc..., but not all those extra functions) it will work.

So maybe it is better to write an abstraction layer in C++ that can be used directly from D.

Other than that, Skia is a good test case for D's C++ support.

Actually I tried this as quick hack and it writes text on top of C API demo.

So it is indeed just thin wrapper, and it makes possible to extend bindings to load text functions on top of it.

HACK: DO NOT USE

main.d (add on top)

extern(C++)
{
    class SkPaint;

    alias SkScalar = float;

    enum SkTextEncoding
    {
        kUTF8,      //!< uses bytes to represent UTF-8 or ASCII
        kUTF16,     //!< uses two byte words to represent most of Unicode
        kUTF32,     //!< uses four byte words to represent all of Unicode
        kGlyphID,   //!< uses two byte words to represent glyph indices
    }

    final class SkCanvas
    {
        void drawSimpleText(const(void)* text, size_t byteLength, SkTextEncoding encoding,
                            SkScalar x, SkScalar y, ref const SkFont font, ref const SkPaint paint);

        alias drawSimpleTextFn = void function(SkCanvas this_,
                            const(void)* text, size_t byteLength, SkTextEncoding encoding,
                            SkScalar x, SkScalar y, ref const SkFont font, ref const SkPaint paint);
    }

    extern(C++, class)
    struct SkFont
    {
        byte[256] instanceData_; // hack, reserve enough space to fit all data, since I don't know actual size

        //@disable this();
        //pragma(msg, SkFont.__ctor.mangleof);

        alias ctorFn = void function(SkFont* this_);
    }
}

main.d (insert at the end of draw function before delete block)

void draw(sk_canvas_t* canvas) {
    // ...

    sk_paint_t* strokeText = sk_paint_new();
    sk_paint_set_stroke(strokeText, true);
    sk_paint_set_stroke_width(strokeText, 1.0f);

    import core.sys.windows.windows;
    auto lib = LoadLibrary("skia.dll");
    SkCanvas.drawSimpleTextFn drawTextFnPtr = cast(SkCanvas.drawSimpleTextFn) GetProcAddress(lib, "?drawSimpleText@SkCanvas@@QEAAXPEBX_KW4SkTextEncoding@@MMAEBVSkFont@@AEBVSkPaint@@@Z");

    SkFont fnt;
    SkFont.ctorFn skFontCtorPtr = cast(SkFont.ctorFn) GetProcAddress(lib, "??0SkFont@@QEAA@XZ");
    skFontCtorPtr(&fnt);

    enum text = "test dynamic text";
    drawTextFnPtr(cast(SkCanvas)canvas, text.ptr, text.length, SkTextEncoding.kUTF8, 150, 150, fnt, *cast(SkPaint*) strokeText);

    sk_paint_delete(strokeText);

    // deleters
}
June 07, 2021
Am 04.06.2021 um 03:11 schrieb Adam D. Ruppe:
> On Friday, 4 June 2021 at 00:52:21 UTC, rikki cattermole wrote:
>> That only includes static linking (both objects and shared libraries).
> 
> Well, if importc works as well as claimed, it would be trivial to do a dynamic load off it using the same pattern I did in simpledisplay's dynamic loader: reflect over the static stuff and mix in dynamic stuff from it.

FWIW, I've also made a little library a while ago that does this. It probably doesn't handle all attributes correctly, but otherwise works for any static binding: https://code.dlang.org/packages/dynamic

1 2
Next ›   Last »