PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
D | 72 lines | 59 code | 10 blank | 3 comment | 2 complexity | fad454d46881b98f6ea0e8d267da0abe 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 std.stdio;
  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. writefln( "Variables (printed from D):" );
  24. writefln( "ivar = %s", example.ivar );
  25. writefln( "svar = %s", example.svar );
  26. writefln( "lvar = %s", example.lvar );
  27. writefln( "uivar = %s", example.uivar );
  28. writefln( "usvar = %s", example.usvar );
  29. writefln( "ulvar = %s", example.ulvar );
  30. writefln( "scvar = %s", example.scvar );
  31. writefln( "ucvar = %s", example.ucvar );
  32. writefln( "fvar = %s", example.fvar );
  33. writefln( "dvar = %s", example.dvar );
  34. writefln( "cvar = %s", example.cvar );
  35. writefln( "strvar = %s", example.strvar );
  36. writefln( "cstrvar = %s", example.cstrvar );
  37. writefln( "iptrvar = %s", example.iptrvar );
  38. writefln( "name = %s", example.name );
  39. writefln( "ptptr = %s %s", example.ptptr, example.Point_print(example.ptptr) );
  40. writefln( "pt = %s %s", example.pt, example.Point_print(example.pt) );
  41. writefln( "status = %s", example.status );
  42. writefln( "\nVariables (printed from the C library):" );
  43. example.print_vars();
  44. writefln( "\nNow I'm going to try and modify some read only variables:" );
  45. writefln( "Checking that the read only variables are readonly..." );
  46. writeln( " 'path'..." );
  47. static if ( is( typeof( example.path = "a" ) ) )
  48. writefln("Oh dear, this variable is not read only!");
  49. else
  50. writefln("Good.");
  51. writeln( " 'status'..." );
  52. static if ( is( typeof( example.status = 2 ) ) )
  53. writefln("Oh dear, this variable is not read only!");
  54. else
  55. writefln("Good.");
  56. writefln( "\nI'm going to try and update a structure variable:" );
  57. example.pt = example.ptptr;
  58. write( "The new value is " );
  59. stdout.flush();
  60. example.pt_print();
  61. writefln( "You should see the value %s", example.Point_print(example.ptptr) );
  62. }