Reflection?
Rory McGuire
rjmcguire at gmail.com
Tue Oct 26 08:29:32 PDT 2010
To get some basic runtime reflection one could use dmd's json dump.
and then use import("filename.json") to get the json into the
executable. Then make a class which makes it more usable as a
reflection system.
You can try it out by compiling this code twice, first time with a
dummy jsontest.json.
=============jsontest.d=========
// compile with: dmd -J./ -X jsontest.d
import std.stdio;
string jsondata = import("jsontest.json");
int getnumber() {
return 1376;
}
void main() {
writeln("hello world!", getnumber());
writeln(jsondata);
}
===================================
works on linux, output is:
hello world!1376
[
{
"kind" : "module",
"file" : "jsontest.d",
"members" : [
{
"name" : "jsondata",
"kind" : "variable",
"type" : "string",
"line" : 3}
,
{
"name" : "getnumber",
"kind" : "function",
"type" : "int()",
"line" : 5}
,
{
"name" : "main",
"kind" : "function",
"type" : "void()",
"line" : 9}
]
}
]
Regards
-Rory
Sclytrack wrote:
> Instead of targeting doc files, could dmd create xml files
> for the purpose of runtime reflection, instead of trying to
> go to runtime reflection via __traits.
>
> You can archive these files together with the binary code.
> Create some sort of D package.
>
> I mean C (GNOME) is going with xml files for their introspection.
> http://library.gnome.org/devel/gi/unstable/gi-gir-reference.html
>
> ---------------------------------------------------------
> dmd is a 42 bit compiler.
> oh W. just added another bit.
> dmd is now a 43 bit compiler.
> ---------------------------------------------------------
More information about the Digitalmars-d
mailing list