reflection / D's function calling convention?
Thomas Kuehne
thomas-dloop at kuehne.cn
Tue Oct 31 18:59:27 PST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Is D's functions calling convention somewhere documented?
I've been tinkering with a reflection module for D.
Gaining access to all dynamic and static symbols is
currently possible as well as calling C functions
(see below) but calling functions with D linkage isn't
yet implemented:
#
# import kuehne.reflection;
#
# int main(){
# Symbol s = symbols["strlen"];
#
# char* test = "unter den Birnen";
# size_t len = 0;
#
# Argument[] arg = new Argument[1];
# arg[0].size = test.sizeof;
# arg[0].data = &test;
#
# Argument[] result;
# result = s.call(CallingConvention.C, arg);
# foreach(x; result){
# if(x.type == "<?>"){
# len = *(cast(size_t*) x.data);
# break;
# }
# }
#
# printf("strlen('%s') -> %zu", test, len);
# return 0;
# }
output:
>
> strlen('unter den Birnen') -> 16
>
Thomas
-----BEGIN PGP SIGNATURE-----
iD8DBQFFSBqALK5blCcjpWoRArGZAJ4uf0tgdH2pQdaFL6KIFtVfnu9sMACdHiVN
LLWDFZ6wUzPJo+q0PUWfPaU=
=NJ5g
-----END PGP SIGNATURE-----
More information about the Digitalmars-d
mailing list