Created
April 16, 2012 23:09
-
-
Save JakobOvrum/2402242 to your computer and use it in GitHub Desktop.
thiscall
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.traits; | |
// Simplified version; does not work with a large number of possible types for F | |
private extern(C++) interface Thiscall(F) | |
{ | |
ReturnType!F cppfunc(ParameterTypeTuple!F args); | |
} | |
auto thiscall(F, Args...)(void* _this, F func, Args args) | |
{ | |
void*[2] vtable; | |
vtable[0] = _this; | |
vtable[1] = func; | |
auto i = cast(Thiscall!F)&vtable; | |
return i.cppfunc(args); | |
} | |
void main() | |
{ | |
void* obj = null; | |
int function(int) member = null; | |
int a = thiscall(obj, member, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment