PageRenderTime 91ms CodeModel.GetById 16ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. // This example illustrates global variable access from C#.
  2. module runme;
  3. import tango.io.Stdout;
  4. static import example;
  5. void main() {
  6. // Try to set the values of some global variables
  7. example.ivar = 42;
  8. example.svar = -31000;
  9. example.lvar = 65537;
  10. example.uivar = 123456;
  11. example.usvar = 61000;
  12. example.ulvar = 654321;
  13. example.scvar = -13;
  14. example.ucvar = 251;
  15. example.cvar = 'S';
  16. example.fvar = 3.14159f;
  17. example.dvar = 2.1828;
  18. example.strvar = "Hello World";
  19. example.iptrvar = example.new_int(37);
  20. example.ptptr = example.new_Point(37,42);
  21. example.name = "Bill";
  22. // Now print out the values of the variables
  23. Stdout.formatln( "Variables (printed from D):" );
  24. Stdout.formatln( "ivar = {}", example.ivar );
  25. Stdout.formatln( "svar = {}", example.svar );
  26. Stdout.formatln( "lvar = {}", example.lvar );
  27. Stdout.formatln( "uivar = {}", example.uivar );
  28. Stdout.formatln( "usvar = {}", example.usvar );
  29. Stdout.formatln( "ulvar = {}", example.ulvar );
  30. Stdout.formatln( "scvar = {}", example.scvar );
  31. Stdout.formatln( "ucvar = {}", example.ucvar );
  32. Stdout.formatln( "fvar = {}", example.fvar );
  33. Stdout.formatln( "dvar = {}", example.dvar );
  34. Stdout.formatln( "cvar = {}", example.cvar );
  35. Stdout.formatln( "strvar = {}", example.strvar );
  36. Stdout.formatln( "cstrvar = {}", example.cstrvar );
  37. Stdout.formatln( "iptrvar = {}", example.iptrvar );
  38. Stdout.formatln( "name = {}", example.name );
  39. Stdout.formatln( "ptptr = {} {}", example.ptptr, example.Point_print(example.ptptr) );
  40. Stdout.formatln( "pt = {} {}", example.pt, example.Point_print(example.pt) );
  41. Stdout.formatln( "status = {}", example.status );
  42. Stdout.formatln( "\nVariables (printed from the C library):" );
  43. example.print_vars();
  44. Stdout.formatln( "\nNow I'm going to try and modify some read only variables:" );
  45. Stdout.formatln( "Checking that the read only variables are readonly..." );
  46. Stdout( " 'path'..." );
  47. static if ( is( typeof( example.path = "a" ) ) )
  48. Stdout.formatln("Oh dear, this variable is not read only!");
  49. else
  50. Stdout.formatln("Good.");
  51. Stdout( " 'status'..." );
  52. static if ( is( typeof( example.status = 2 ) ) )
  53. Stdout.formatln("Oh dear, this variable is not read only!");
  54. else
  55. Stdout.formatln("Good.");
  56. Stdout.formatln( "\nI'm going to try and update a structure variable:" );
  57. example.pt = example.ptptr;
  58. Stdout( "The new value is " ).flush;
  59. example.pt_print();
  60. Stdout.formatln( "You should see the value {}", example.Point_print(example.ptptr) );
  61. }