Friday, August 11, 2017

dlang - retrieve struct from void pointer passed to extern (C) function

struct Data {
    int depth;
}

extern (C) void startElement(void* userData, const(char)* name, const(char*)* atts) nothrow
{

    Data user_data = (*cast(Data*) userData);
    user_data.depth++;
    // and so forth



I do not know if this is the right way to do it but it seems to work.