Removed sockets from 'debugger.nit' to put them in 'debugger_socket.nit
[nit.git] / examples / calculator.nit
index 32c2f72..541f4d2 100644 (file)
@@ -57,6 +57,7 @@ class CalculatorContext
 
        fun switch_to_decimals
        do
+               if self.current == null then current = 0.0
                if after_point != null then return
 
                after_point = -1
@@ -112,17 +113,17 @@ class CalculatorGui
                if user_data isa Char then # is an operation
                        var c = user_data
                        if c == '.' then
-                                       but_dot.set_sensitive= false
-                                       context.switch_to_decimals
-                                       lbl_disp.text = "{context.current.to_i}."
+                               but_dot.sensitive= false
+                               context.switch_to_decimals
+                               lbl_disp.text = "{context.current.to_i}."
                        else
-                               but_dot.set_sensitive= true
+                               but_dot.sensitive= true
                                context.push_op( c )
                                
                                var s = context.result.to_precision_native(6)
                                var index : nullable Int = null
                                for i in s.length.times do
-                                   var chiffre = s[i]
+                                   var chiffre = s.chars[i]
                                    if chiffre == '0' and index == null then
                                        index = i
                                    else if chiffre != '0' then
@@ -131,7 +132,7 @@ class CalculatorGui
                                end
                                if index != null then
                                        s = s.substring(0, index)
-                                       if s[s.length-1] == ',' then s = s.substring(0, s.length-1)
+                                       if s.chars[s.length-1] == ',' then s = s.substring(0, s.length-1)
                                end
                                lbl_disp.text = s
                        end