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