PageRenderTime 51ms CodeModel.GetById 24ms app.highlight 21ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Examples/d/variables/d1/runme.d

#
D | 71 lines | 58 code | 10 blank | 3 comment | 2 complexity | 9cb221c52eb90322378a9bb02e9204f8 MD5 | raw file
 1// This example illustrates global variable access from C#.
 2module runme;
 3
 4import tango.io.Stdout;
 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  Stdout.formatln( "Variables (printed from D):" );
27  Stdout.formatln( "ivar      = {}", example.ivar );
28  Stdout.formatln( "svar      = {}", example.svar );
29  Stdout.formatln( "lvar      = {}", example.lvar );
30  Stdout.formatln( "uivar     = {}", example.uivar );
31  Stdout.formatln( "usvar     = {}", example.usvar );
32  Stdout.formatln( "ulvar     = {}", example.ulvar );
33  Stdout.formatln( "scvar     = {}", example.scvar );
34  Stdout.formatln( "ucvar     = {}", example.ucvar );
35  Stdout.formatln( "fvar      = {}", example.fvar );
36  Stdout.formatln( "dvar      = {}", example.dvar );
37  Stdout.formatln( "cvar      = {}", example.cvar );
38  Stdout.formatln( "strvar    = {}", example.strvar );
39  Stdout.formatln( "cstrvar   = {}", example.cstrvar );
40  Stdout.formatln( "iptrvar   = {}", example.iptrvar );
41  Stdout.formatln( "name      = {}", example.name );
42  Stdout.formatln( "ptptr     = {} {}", example.ptptr, example.Point_print(example.ptptr) );
43  Stdout.formatln( "pt        = {} {}", example.pt, example.Point_print(example.pt) );
44  Stdout.formatln( "status    = {}", example.status );
45
46  Stdout.formatln( "\nVariables (printed from the C library):" );
47  example.print_vars();
48
49  Stdout.formatln( "\nNow I'm going to try and modify some read only variables:" );
50  Stdout.formatln( "Checking that the read only variables are readonly..." );
51
52  Stdout( "     'path'..." );
53  static if ( is( typeof( example.path = "a" ) ) )
54    Stdout.formatln("Oh dear, this variable is not read only!");
55  else
56    Stdout.formatln("Good.");
57
58  Stdout( "     'status'..." );
59  static if ( is( typeof( example.status = 2 ) ) )
60    Stdout.formatln("Oh dear, this variable is not read only!");
61  else
62    Stdout.formatln("Good.");
63
64  Stdout.formatln( "\nI'm going to try and update a structure variable:" );
65
66  example.pt = example.ptptr;
67
68  Stdout( "The new value is " ).flush;
69  example.pt_print();
70  Stdout.formatln( "You should see the value {}", example.Point_print(example.ptptr) );
71}