PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/ruby/reference/runme.rb

#
Ruby | 60 lines | 17 code | 15 blank | 28 comment | 0 complexity | 3ce2716ba2d047d57fc9609452c165de MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. # file: runme.rb
  2. # This file illustrates the manipulation of C++ references in Ruby.
  3. require 'example'
  4. # ----- Object creation -----
  5. print "Creating some objects:\n"
  6. a = Example::Vector.new(3,4,5)
  7. b = Example::Vector.new(10,11,12)
  8. print " Created ", a.print, "\n"
  9. print " Created ", b.print, "\n"
  10. # ----- Call an overloaded operator -----
  11. # This calls the wrapper we placed around
  12. #
  13. # operator+(const Vector &a, const Vector &)
  14. #
  15. # It returns a new allocated object.
  16. print "Adding a+b\n"
  17. c = Example::addv(a, b)
  18. print " a+b = ", c.print, "\n"
  19. # ----- Create a vector array -----
  20. print "Creating an array of vectors\n"
  21. va = Example::VectorArray.new(10)
  22. print " va = #{va}\n"
  23. # ----- Set some values in the array -----
  24. # These operators copy the value of a and b to the vector array
  25. va.set(0, a)
  26. va.set(1, b)
  27. va.set(2, Example::addv(a,b))
  28. c = Example::addv(a,b)
  29. va.set(3, c)
  30. =begin commented out due to GC issue
  31. # Get some values from the array
  32. print "Getting some array values\n"
  33. for i in 0...5
  34. print " va(#{i}) = ", va.get(i).print, "\n"
  35. end
  36. # Watch under resource meter to check on this
  37. print "Making sure we don't leak memory.\n"
  38. for i in 0...1000000
  39. c = va.get(i % 10)
  40. end
  41. =end