PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/ruby/variables/runme.rb

#
Ruby | 77 lines | 60 code | 14 blank | 3 comment | 0 complexity | 31e8fc7598dd88a20deedacb0c205041 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. # file: runme.rb
  2. require 'example'
  3. # Try to set the values of some global variables
  4. Example.ivar = 42
  5. Example.svar = -31000
  6. Example.lvar = 65537
  7. Example.uivar = 123456
  8. Example.usvar = 61000
  9. Example.ulvar = 654321
  10. Example.scvar = -13
  11. Example.ucvar = 251
  12. Example.cvar = "S"
  13. Example.fvar = 3.14159
  14. Example.dvar = 2.1828
  15. Example.strvar = "Hello World"
  16. Example.iptrvar= Example.new_int(37)
  17. Example.ptptr = Example.new_Point(37,42)
  18. Example.name = "Bill"
  19. # Now print out the values of the variables
  20. puts "Variables (values printed from Ruby)"
  21. puts "ivar = #{Example.ivar}"
  22. puts "svar = #{Example.svar}"
  23. puts "lvar = #{Example.lvar}"
  24. puts "uivar = #{Example.uivar}"
  25. puts "usvar = #{Example.usvar}"
  26. puts "ulvar = #{Example.ulvar}"
  27. puts "scvar = #{Example.scvar}"
  28. puts "ucvar = #{Example.ucvar}"
  29. puts "fvar = #{Example.fvar}"
  30. puts "dvar = #{Example.dvar}"
  31. puts "cvar = #{Example.cvar}"
  32. puts "strvar = #{Example.strvar}"
  33. puts "cstrvar = #{Example.cstrvar}"
  34. puts "iptrvar = #{Example.iptrvar}"
  35. puts "name = #{Example.name}"
  36. puts "ptptr = #{Example.ptptr} (#{Example.Point_print(Example.ptptr)})"
  37. puts "pt = #{Example.pt} (#{Example.Point_print(Example.pt)})"
  38. puts "\nVariables (values printed from C)"
  39. Example.print_vars()
  40. puts "\nNow I'm going to try and modify some read only variables";
  41. puts " Tring to set 'path'";
  42. begin
  43. Example.path = "Whoa!"
  44. puts "Hey, what's going on?!?! This shouldn't work"
  45. rescue NameError
  46. puts "Good."
  47. end
  48. puts " Trying to set 'status'";
  49. begin
  50. Example.status = 0
  51. puts "Hey, what's going on?!?! This shouldn't work"
  52. rescue NameError
  53. puts "Good."
  54. end
  55. puts "\nI'm going to try and update a structure variable.\n"
  56. Example.pt = Example.ptptr
  57. puts "The new value is"
  58. Example.pt_print()
  59. puts "You should see the value #{Example.Point_print(Example.ptptr)}"