d取方法的所有者
//extern (C) public int registerDDelegate(alias Func,...)
class C {
string s;
void foo() {
import std.stdio : writeln;
writeln("看", s, "用D!");
}
}
auto luaGetFromIndex(C)() {
auto c = new C();
c.s = "lua中创建";
return c;
}
extern (C)
int registerDDelegate(alias Func)() {
import std.traits : Parameters;
alias ClassType = Parameters!Func[0];
auto c = luaGetFromIndex!ClassType();
Func(c);
return 0;
}
void main() {
// λ取c
registerDDelegate!((C c) => c.foo);
}
浙公网安备 33010602011771号