You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have extern (C) int sortList1(GtkListBoxRow* _row1, GtkListBoxRow* _row2, void* userData)
I pass it as listbox.setSortFunc(&sortList1, cast(void*)this, &_destroy2);
In the sortList1 function I want to access derived members of my ListBoxRowWithData such as:
auto row1 = cast(ListBoxRowWithData)getMyDObject!ListBoxRow(_row1);
auto row2 = cast(ListBoxRowWithData)getMyDObject!ListBoxRow(_row2);
if(row1.id < row2.id) return1;
A regular cast returns null. T opCast(T)() in ObjectG.d returns null in this case. I dug into the sources a little, and my working solution is like:
templategetCType(T)
{
staticif ( is(T ==class) )
alias getCType = typeof(T.tupleof[0]);
elsealias getCType = void*;
}
T getMyDObject(T, TC = getCType!T)(void* data){
T ret = ObjectG.getDObject!(T)(cast(TC)data);
return ret;
}
Is there an existing implementation for T getMyDObject(T, TC = getCType!T)(void* data)?
The text was updated successfully, but these errors were encountered:
aferust
changed the title
Is there an explicit public function to get D Classes from Ctype*?
Is there an explicit public function to get D Classes from StructCtype*?
Nov 6, 2020
For instance,
I have
extern (C) int sortList1(GtkListBoxRow* _row1, GtkListBoxRow* _row2, void* userData)
I pass it as
listbox.setSortFunc(&sortList1, cast(void*)this, &_destroy2);
In the sortList1 function I want to access derived members of my ListBoxRowWithData such as:
A regular cast returns null. T opCast(T)() in ObjectG.d returns null in this case. I dug into the sources a little, and my working solution is like:
Is there an existing implementation for
T getMyDObject(T, TC = getCType!T)(void* data)
?The text was updated successfully, but these errors were encountered: