PageRenderTime 22ms CodeModel.GetById 8ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/trunk/Examples/d/variables/d2/runme.d

#
D | 72 lines | 59 code | 10 blank | 3 comment | 2 complexity | fad454d46881b98f6ea0e8d267da0abe MD5 | raw file
 1// This example illustrates global variable access from C#.
 2module runme;
 3
 4import std.stdio;
 5static import example;
 6
 7void main() {
 8  // Try to set the values of some global variables
 9  example.ivar    =  42;
10  example.svar    = -31000;
11  example.lvar    =  65537;
12  example.uivar   =  123456;
13  example.usvar   =  61000;
14  example.ulvar   =  654321;
15  example.scvar   =  -13;
16  example.ucvar   =  251;
17  example.cvar    =  'S';
18  example.fvar    =  3.14159f;
19  example.dvar    =  2.1828;
20  example.strvar  =  "Hello World";
21  example.iptrvar = example.new_int(37);
22  example.ptptr   = example.new_Point(37,42);
23  example.name    = "Bill";
24
25  // Now print out the values of the variables
26  writefln( "Variables (printed from D):" );
27  writefln( "ivar      = %s", example.ivar );
28  writefln( "svar      = %s", example.svar );
29  writefln( "lvar      = %s", example.lvar );
30  writefln( "uivar     = %s", example.uivar );
31  writefln( "usvar     = %s", example.usvar );
32  writefln( "ulvar     = %s", example.ulvar );
33  writefln( "scvar     = %s", example.scvar );
34  writefln( "ucvar     = %s", example.ucvar );
35  writefln( "fvar      = %s", example.fvar );
36  writefln( "dvar      = %s", example.dvar );
37  writefln( "cvar      = %s", example.cvar );
38  writefln( "strvar    = %s", example.strvar );
39  writefln( "cstrvar   = %s", example.cstrvar );
40  writefln( "iptrvar   = %s", example.iptrvar );
41  writefln( "name      = %s", example.name );
42  writefln( "ptptr     = %s %s", example.ptptr, example.Point_print(example.ptptr) );
43  writefln( "pt        = %s %s", example.pt, example.Point_print(example.pt) );
44  writefln( "status    = %s", example.status );
45
46  writefln( "\nVariables (printed from the C library):" );
47  example.print_vars();
48
49  writefln( "\nNow I'm going to try and modify some read only variables:" );
50  writefln( "Checking that the read only variables are readonly..." );
51
52  writeln( "     'path'..." );
53  static if ( is( typeof( example.path = "a" ) ) )
54    writefln("Oh dear, this variable is not read only!");
55  else
56    writefln("Good.");
57
58  writeln( "     'status'..." );
59  static if ( is( typeof( example.status = 2 ) ) )
60    writefln("Oh dear, this variable is not read only!");
61  else
62    writefln("Good.");
63
64  writefln( "\nI'm going to try and update a structure variable:" );
65
66  example.pt = example.ptptr;
67
68  write( "The new value is " );
69  stdout.flush();
70  example.pt_print();
71  writefln( "You should see the value %s", example.Point_print(example.ptptr) );
72}