gloo 1.4.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.gitignore +1 -0
  4. data/gloo.gemspec +0 -2
  5. data/lib/VERSION +1 -1
  6. data/lib/dependencies.rb +4 -4
  7. data/lib/gloo/app/args.rb +112 -0
  8. data/lib/gloo/app/engine.rb +247 -0
  9. data/lib/gloo/app/engine_context.rb +25 -0
  10. data/lib/gloo/app/info.rb +20 -3
  11. data/lib/gloo/app/log.rb +73 -1
  12. data/lib/gloo/app/mode.rb +27 -0
  13. data/lib/gloo/app/platform.rb +8 -1
  14. data/lib/gloo/app/settings.rb +202 -0
  15. data/lib/gloo/convert/converter.rb +42 -0
  16. data/lib/gloo/convert/string_to_date.rb +21 -0
  17. data/lib/gloo/convert/string_to_datetime.rb +21 -0
  18. data/lib/gloo/convert/string_to_decimal.rb +20 -0
  19. data/lib/gloo/convert/string_to_integer.rb +20 -0
  20. data/lib/gloo/convert/string_to_time.rb +21 -0
  21. data/lib/gloo/core/baseo.rb +31 -0
  22. data/lib/gloo/core/dictionary.rb +245 -0
  23. data/lib/gloo/core/error.rb +61 -0
  24. data/lib/gloo/core/event_manager.rb +45 -0
  25. data/lib/gloo/core/factory.rb +211 -0
  26. data/lib/gloo/core/gloo_system.rb +267 -0
  27. data/lib/gloo/core/heap.rb +53 -0
  28. data/lib/gloo/core/here.rb +36 -0
  29. data/lib/gloo/core/it.rb +36 -0
  30. data/lib/gloo/core/literal.rb +30 -0
  31. data/lib/gloo/core/obj.rb +318 -0
  32. data/lib/gloo/core/obj_finder.rb +30 -0
  33. data/lib/gloo/core/op.rb +40 -0
  34. data/lib/gloo/core/parser.rb +60 -0
  35. data/lib/gloo/core/pn.rb +212 -0
  36. data/lib/gloo/core/tokens.rb +165 -0
  37. data/lib/gloo/core/verb.rb +87 -0
  38. data/lib/gloo/exec/action.rb +48 -0
  39. data/lib/gloo/exec/dispatch.rb +40 -0
  40. data/lib/gloo/exec/exec_env.rb +75 -0
  41. data/lib/gloo/exec/runner.rb +45 -0
  42. data/lib/gloo/exec/script.rb +50 -0
  43. data/lib/gloo/exec/stack.rb +79 -0
  44. data/lib/gloo/expr/expression.rb +119 -0
  45. data/lib/gloo/expr/l_boolean.rb +36 -0
  46. data/lib/gloo/expr/l_decimal.rb +39 -0
  47. data/lib/gloo/expr/l_integer.rb +37 -0
  48. data/lib/gloo/expr/l_string.rb +58 -0
  49. data/lib/gloo/expr/op_div.rb +22 -0
  50. data/lib/gloo/expr/op_minus.rb +22 -0
  51. data/lib/gloo/expr/op_mult.rb +22 -0
  52. data/lib/gloo/expr/op_plus.rb +24 -0
  53. data/lib/gloo/objs/basic/alias.rb +78 -0
  54. data/lib/gloo/objs/basic/boolean.rb +120 -0
  55. data/lib/gloo/objs/basic/container.rb +65 -0
  56. data/lib/gloo/objs/basic/decimal.rb +76 -0
  57. data/lib/gloo/objs/basic/integer.rb +73 -0
  58. data/lib/gloo/objs/basic/script.rb +99 -0
  59. data/lib/gloo/objs/basic/string.rb +77 -0
  60. data/lib/gloo/objs/basic/text.rb +79 -0
  61. data/lib/gloo/objs/basic/untyped.rb +41 -0
  62. data/lib/gloo/objs/cli/banner.rb +1 -1
  63. data/lib/gloo/objs/cli/bar.rb +3 -3
  64. data/lib/gloo/objs/cli/colorize.rb +1 -1
  65. data/lib/gloo/objs/cli/confirm.rb +1 -1
  66. data/lib/gloo/objs/cli/menu.rb +6 -6
  67. data/lib/gloo/objs/cli/menu_item.rb +1 -1
  68. data/lib/gloo/objs/cli/pastel.rb +1 -1
  69. data/lib/gloo/objs/cli/prompt.rb +1 -1
  70. data/lib/gloo/objs/cli/select.rb +2 -2
  71. data/lib/gloo/objs/ctrl/each.rb +279 -0
  72. data/lib/gloo/objs/ctrl/repeat.rb +108 -0
  73. data/lib/gloo/objs/data/markdown.rb +79 -0
  74. data/lib/gloo/objs/data/mysql.rb +5 -5
  75. data/lib/gloo/objs/data/query.rb +4 -4
  76. data/lib/gloo/objs/data/sqlite.rb +1 -1
  77. data/lib/gloo/objs/data/table.rb +112 -0
  78. data/lib/gloo/objs/dev/git.rb +2 -2
  79. data/lib/gloo/objs/dev/stats.rb +4 -4
  80. data/lib/gloo/objs/dt/date.rb +65 -0
  81. data/lib/gloo/objs/dt/datetime.rb +120 -0
  82. data/lib/gloo/objs/dt/dt_tools.rb +100 -0
  83. data/lib/gloo/objs/dt/time.rb +65 -0
  84. data/lib/gloo/objs/ror/erb.rb +116 -0
  85. data/lib/gloo/objs/ror/eval.rb +107 -0
  86. data/lib/gloo/objs/snd/play.rb +1 -1
  87. data/lib/gloo/objs/snd/say.rb +1 -1
  88. data/lib/gloo/objs/system/file_handle.rb +4 -4
  89. data/lib/gloo/objs/system/ssh_exec.rb +1 -1
  90. data/lib/gloo/objs/system/system.rb +1 -1
  91. data/lib/gloo/objs/web/http_get.rb +159 -0
  92. data/lib/gloo/objs/web/http_post.rb +183 -0
  93. data/lib/gloo/objs/web/json.rb +135 -0
  94. data/lib/gloo/objs/web/slack.rb +130 -0
  95. data/lib/gloo/objs/web/teams.rb +117 -0
  96. data/lib/gloo/objs/web/uri.rb +148 -0
  97. data/lib/gloo/persist/disc_mech.rb +87 -0
  98. data/lib/gloo/persist/file_loader.rb +193 -0
  99. data/lib/gloo/persist/file_saver.rb +51 -0
  100. data/lib/gloo/persist/file_storage.rb +46 -0
  101. data/lib/gloo/persist/line_splitter.rb +81 -0
  102. data/lib/gloo/persist/persist_man.rb +153 -0
  103. data/lib/gloo/utils/format.rb +21 -0
  104. data/lib/gloo/utils/stats.rb +206 -0
  105. data/lib/gloo/utils/words.rb +19 -0
  106. data/lib/gloo/verbs/alert.rb +2 -2
  107. data/lib/gloo/verbs/beep.rb +1 -1
  108. data/lib/gloo/verbs/cls.rb +1 -1
  109. data/lib/gloo/verbs/context.rb +62 -0
  110. data/lib/gloo/verbs/create.rb +68 -0
  111. data/lib/gloo/verbs/execute.rb +56 -0
  112. data/lib/gloo/verbs/files.rb +49 -0
  113. data/lib/gloo/verbs/help.rb +1 -1
  114. data/lib/gloo/verbs/if.rb +92 -0
  115. data/lib/gloo/verbs/list.rb +98 -0
  116. data/lib/gloo/verbs/load.rb +45 -0
  117. data/lib/gloo/verbs/move.rb +89 -0
  118. data/lib/gloo/verbs/put.rb +94 -0
  119. data/lib/gloo/verbs/quit.rb +40 -0
  120. data/lib/gloo/verbs/reload.rb +43 -0
  121. data/lib/gloo/verbs/run.rb +75 -0
  122. data/lib/gloo/verbs/save.rb +39 -0
  123. data/lib/gloo/verbs/show.rb +63 -0
  124. data/lib/gloo/verbs/tell.rb +80 -0
  125. data/lib/gloo/verbs/unless.rb +92 -0
  126. data/lib/gloo/verbs/unload.rb +46 -0
  127. data/lib/gloo/verbs/version.rb +3 -3
  128. data/lib/gloo/verbs/wait.rb +42 -0
  129. data/lib/gloo.rb +2 -2
  130. data/lib/run.rb +2 -2
  131. metadata +97 -22
@@ -0,0 +1,36 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An Expression that can be evaluated.
5
+ #
6
+
7
+ module Gloo
8
+ module Expr
9
+ class LBoolean < Gloo::Core::Literal
10
+
11
+ #
12
+ # Is the given token a boolean?
13
+ #
14
+ def self.boolean?( token )
15
+ return Gloo::Objs::Boolean.boolean? token
16
+ end
17
+
18
+ #
19
+ # Set the value, converting to an boolean.
20
+ #
21
+ def set_value( value )
22
+ @value = Gloo::Objs::Boolean.coerse_to_bool value
23
+ end
24
+
25
+ #
26
+ # Get string representation
27
+ #
28
+ def to_s
29
+ return 'false' unless @value
30
+
31
+ return @value.to_s
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A literal decimal value.
5
+ #
6
+
7
+ module Gloo
8
+ module Expr
9
+ class LDecimal < Gloo::Core::Literal
10
+
11
+ #
12
+ # Is the given token a decimal?
13
+ #
14
+ def self.decimal?( token )
15
+ return true if token.is_a? Numeric
16
+
17
+ s = token.strip
18
+ return s.to_f.to_s == s
19
+ end
20
+
21
+ #
22
+ # Set the value, converting to an integer.
23
+ #
24
+ def set_value( value )
25
+ value = value.to_s if value.is_a? Numeric
26
+
27
+ @value = value.to_f
28
+ end
29
+
30
+ #
31
+ # Get string representation
32
+ #
33
+ def to_s
34
+ return self.value.to_s
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,37 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An Expression that can be evaluated.
5
+ #
6
+
7
+ module Gloo
8
+ module Expr
9
+ class LInteger < Gloo::Core::Literal
10
+
11
+ #
12
+ # Is the given token an integer?
13
+ #
14
+ def self.integer?( token )
15
+ return true if token.is_a? Integer
16
+
17
+ s = token.strip
18
+ return s.to_i.to_s == s
19
+ end
20
+
21
+ #
22
+ # Set the value, converting to an integer.
23
+ #
24
+ def set_value( value )
25
+ @value = value.to_i
26
+ end
27
+
28
+ #
29
+ # Get string representation
30
+ #
31
+ def to_s
32
+ return self.value.to_s
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,58 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An Expression that can be evaluated.
5
+ #
6
+
7
+ module Gloo
8
+ module Expr
9
+ class LString < Gloo::Core::Literal
10
+
11
+ #
12
+ # Set the value, triming opening and closing
13
+ # quotations if necessary.
14
+ #
15
+ def set_value( value )
16
+ @value = value
17
+ return unless value
18
+
19
+ @value = LString.strip_quotes( @value )
20
+ end
21
+
22
+ #
23
+ # Is the given token a string?
24
+ #
25
+ def self.string?( token )
26
+ return false unless token.is_a? String
27
+ return true if token.start_with?( '"' )
28
+ return true if token.start_with?( "'" )
29
+
30
+ return false
31
+ end
32
+
33
+ #
34
+ # Given a string with leading and trailing quotes,
35
+ # strip them out.
36
+ #
37
+ def self.strip_quotes( str )
38
+ if str.start_with?( '"' )
39
+ str = str[ 1..-1 ]
40
+ str = str[ 0..-2 ] if str.end_with?( '"' )
41
+ return str
42
+ elsif str.start_with?( "'" )
43
+ str = str[ 1..-1 ]
44
+ str = str[ 0..-2 ] if str.end_with?( "'" )
45
+ return str
46
+ end
47
+ end
48
+
49
+ #
50
+ # Get string representation
51
+ #
52
+ def to_s
53
+ return self.value
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,22 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Division operator.
5
+ #
6
+
7
+ module Gloo
8
+ module Expr
9
+ class OpDiv < Gloo::Core::Op
10
+
11
+ #
12
+ # Perform the operation and return the result.
13
+ #
14
+ def perform( left, right )
15
+ return left / right.to_i if left.is_a? Integer
16
+
17
+ return left / right.to_f if left.is_a? Numeric
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Subtraction operator.
5
+ #
6
+
7
+ module Gloo
8
+ module Expr
9
+ class OpMinus < Gloo::Core::Op
10
+
11
+ #
12
+ # Perform the operation and return the result.
13
+ #
14
+ def perform( left, right )
15
+ return left - right.to_i if left.is_a? Integer
16
+
17
+ return left - right.to_f if left.is_a? Numeric
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Multiplication operator.
5
+ #
6
+
7
+ module Gloo
8
+ module Expr
9
+ class OpMult < Gloo::Core::Op
10
+
11
+ #
12
+ # Perform the operation and return the result.
13
+ #
14
+ def perform( left, right )
15
+ return left * right.to_i if left.is_a? Integer
16
+
17
+ return left * right.to_f if left.is_a? Numeric
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Addition operator.
5
+ #
6
+
7
+ module Gloo
8
+ module Expr
9
+ class OpPlus < Gloo::Core::Op
10
+
11
+ #
12
+ # Perform the operation and return the result.
13
+ #
14
+ def perform( left, right )
15
+ return left + right.to_s if left.is_a? String
16
+
17
+ return left + right.to_i if left.is_a? Integer
18
+
19
+ return left + right.to_f if left.is_a? Numeric
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,78 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A String.
5
+ #
6
+
7
+ module Gloo
8
+ module Objs
9
+ class Alias < Gloo::Core::Obj
10
+
11
+ KEYWORD = 'alias'.freeze
12
+ KEYWORD_SHORT = 'ln'.freeze
13
+ ALIAS_REFERENCE = '*'.freeze
14
+
15
+ #
16
+ # The name of the object type.
17
+ #
18
+ def self.typename
19
+ return KEYWORD
20
+ end
21
+
22
+ #
23
+ # The short name of the object type.
24
+ #
25
+ def self.short_typename
26
+ return KEYWORD_SHORT
27
+ end
28
+
29
+ #
30
+ # Set the value with any necessary type conversions.
31
+ #
32
+ def set_value( new_value )
33
+ self.value = new_value.to_s
34
+ end
35
+
36
+ # ---------------------------------------------------------------------
37
+ # Messages
38
+ # ---------------------------------------------------------------------
39
+
40
+ #
41
+ # Get a list of message names that this object receives.
42
+ #
43
+ def self.messages
44
+ return super + %w[resolve]
45
+ end
46
+
47
+ #
48
+ # Check to see if the referenced object exists.
49
+ #
50
+ def msg_resolve
51
+ pn = Gloo::Core::Pn.new( @engine, self.value )
52
+ s = pn.exists?
53
+ @engine.heap.it.set_to s
54
+ return s
55
+ end
56
+
57
+ # ---------------------------------------------------------------------
58
+ # Resolve
59
+ # ---------------------------------------------------------------------
60
+
61
+ #
62
+ # Is the object an alias If so, then resolve it.
63
+ # The ref_name is the name used to refer to the object.
64
+ # If it ends with the * then we won't resolve the alias since
65
+ # we are trying to refer to the alias itself.
66
+ #
67
+ def self.resolve_alias( engine, obj, ref_name = nil )
68
+ return nil unless obj
69
+ return obj unless obj.type_display == Gloo::Objs::Alias.typename
70
+ return obj if ref_name&.end_with?( ALIAS_REFERENCE )
71
+
72
+ ln = Gloo::Core::Pn.new( engine, obj.value )
73
+ return ln.resolve
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,120 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object with an boolean value.
5
+ #
6
+
7
+ module Gloo
8
+ module Objs
9
+ class Boolean < Gloo::Core::Obj
10
+
11
+ KEYWORD = 'boolean'.freeze
12
+ KEYWORD_SHORT = 'bool'.freeze
13
+ TRUE = 'true'.freeze
14
+ FALSE = 'false'.freeze
15
+
16
+ #
17
+ # The name of the object type.
18
+ #
19
+ def self.typename
20
+ return KEYWORD
21
+ end
22
+
23
+ #
24
+ # The short name of the object type.
25
+ #
26
+ def self.short_typename
27
+ return KEYWORD_SHORT
28
+ end
29
+
30
+ #
31
+ # Set the value with any necessary type conversions.
32
+ #
33
+ def set_value( new_value )
34
+ self.value = Gloo::Objs::Boolean.coerse_to_bool( new_value )
35
+ end
36
+
37
+ #
38
+ # Coerse the new value to a boolean value.
39
+ #
40
+ def self.coerse_to_bool( new_value )
41
+ return false if new_value.nil?
42
+
43
+ # I should be able to use this:
44
+ # if new_value.kind_of?( String )
45
+ # but it doesn't work. I don't know why.
46
+ if new_value.class.name == 'String'
47
+ return true if new_value.strip.downcase == TRUE
48
+ return false if new_value.strip.downcase == FALSE
49
+ return true if new_value.strip.downcase == 't'
50
+ return false if new_value.strip.downcase == 'f'
51
+ elsif new_value.class.name == 'Integer'
52
+ return new_value.zero? ? false : true
53
+ end
54
+
55
+ return new_value == true
56
+ end
57
+
58
+ #
59
+ # Is the given token a boolean?
60
+ #
61
+ def self.boolean?( token )
62
+ return true if token == true
63
+ return true if token == false
64
+
65
+ if token.class.name == 'String'
66
+ return true if token.strip.downcase == TRUE
67
+ return true if token.strip.downcase == FALSE
68
+ end
69
+ return false
70
+ end
71
+
72
+ #
73
+ # Get the value for display purposes.
74
+ #
75
+ def value_display
76
+ return value ? TRUE : FALSE
77
+ end
78
+
79
+ # ---------------------------------------------------------------------
80
+ # Messages
81
+ # ---------------------------------------------------------------------
82
+
83
+ #
84
+ # Get a list of message names that this object receives.
85
+ #
86
+ def self.messages
87
+ return super + %w[not true false]
88
+ end
89
+
90
+ #
91
+ # Set the value to the opposite of what it is.
92
+ #
93
+ def msg_not
94
+ v = !value
95
+ set_value v
96
+ @engine.heap.it.set_to v
97
+ return v
98
+ end
99
+
100
+ #
101
+ # Set the value to true.
102
+ #
103
+ def msg_true
104
+ set_value true
105
+ @engine.heap.it.set_to true
106
+ return true
107
+ end
108
+
109
+ #
110
+ # Set the value to false.
111
+ #
112
+ def msg_false
113
+ set_value false
114
+ @engine.heap.it.set_to false
115
+ return false
116
+ end
117
+
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,65 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object that contains a collection of other objects.
5
+ #
6
+
7
+ module Gloo
8
+ module Objs
9
+ class Container < Gloo::Core::Obj
10
+
11
+ KEYWORD = 'container'.freeze
12
+ KEYWORD_SHORT = 'can'.freeze
13
+
14
+ #
15
+ # The name of the object type.
16
+ #
17
+ def self.typename
18
+ return KEYWORD
19
+ end
20
+
21
+ #
22
+ # The short name of the object type.
23
+ #
24
+ def self.short_typename
25
+ return KEYWORD_SHORT
26
+ end
27
+
28
+ # ---------------------------------------------------------------------
29
+ # Messages
30
+ # ---------------------------------------------------------------------
31
+
32
+ #
33
+ # Get a list of message names that this object receives.
34
+ #
35
+ def self.messages
36
+ return super + %w[count delete_children show_key_value_table]
37
+ end
38
+
39
+ #
40
+ # Count the number of children in the container.
41
+ #
42
+ def msg_count
43
+ i = child_count
44
+ @engine.heap.it.set_to i
45
+ return i
46
+ end
47
+
48
+ #
49
+ # Delete all children in the container.
50
+ #
51
+ def msg_delete_children
52
+ self.delete_children
53
+ end
54
+
55
+ #
56
+ # Show the given table data.
57
+ #
58
+ def msg_show_key_value_table
59
+ data = self.children.map { |o| [ o.name, o.value ] }
60
+ @engine.platform.show_table nil, data, title
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,76 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # An object with a decimal value.
5
+ #
6
+
7
+ module Gloo
8
+ module Objs
9
+ class Decimal < Gloo::Core::Obj
10
+
11
+ KEYWORD = 'decimal'.freeze
12
+ KEYWORD_SHORT = 'num'.freeze
13
+
14
+ #
15
+ # The name of the object type.
16
+ #
17
+ def self.typename
18
+ return KEYWORD
19
+ end
20
+
21
+ #
22
+ # The short name of the object type.
23
+ #
24
+ def self.short_typename
25
+ return KEYWORD_SHORT
26
+ end
27
+
28
+ #
29
+ # Set the value with any necessary type conversions.
30
+ #
31
+ def set_value( new_value )
32
+ if new_value.nil?
33
+ self.value = 0.0
34
+ return
35
+ end
36
+
37
+ unless new_value.is_a? Numeric
38
+ self.value = @engine.converter.convert( new_value, 'Decimal', 0.0 )
39
+ return
40
+ end
41
+
42
+ self.value = new_value.to_f
43
+ end
44
+
45
+ # ---------------------------------------------------------------------
46
+ # Messages
47
+ # ---------------------------------------------------------------------
48
+
49
+ #
50
+ # Get a list of message names that this object receives.
51
+ #
52
+ def self.messages
53
+ return super + %w[round]
54
+ end
55
+
56
+ #
57
+ # Round the value to a whole value.
58
+ # If a parameter is included in the message,
59
+ # round to the precision given.
60
+ #
61
+ def msg_round
62
+ data = 0
63
+ if @params&.token_count&.positive?
64
+ expr = Gloo::Expr::Expression.new( @engine, @params.tokens )
65
+ data = expr.evaluate.to_i
66
+ end
67
+
68
+ i = self.value.round( data )
69
+ set_value i
70
+ @engine.heap.it.set_to i
71
+ return i
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,73 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object with an integer value.
5
+ #
6
+
7
+ module Gloo
8
+ module Objs
9
+ class Integer < Gloo::Core::Obj
10
+
11
+ KEYWORD = 'integer'.freeze
12
+ KEYWORD_SHORT = 'int'.freeze
13
+
14
+ #
15
+ # The name of the object type.
16
+ #
17
+ def self.typename
18
+ return KEYWORD
19
+ end
20
+
21
+ #
22
+ # The short name of the object type.
23
+ #
24
+ def self.short_typename
25
+ return KEYWORD_SHORT
26
+ end
27
+
28
+ #
29
+ # Set the value with any necessary type conversions.
30
+ #
31
+ def set_value( new_value )
32
+ unless new_value.is_a? Numeric
33
+ self.value = @engine.converter.convert( new_value, 'Integer', 0 )
34
+ return
35
+ end
36
+
37
+ self.value = new_value.to_i
38
+ end
39
+
40
+ # ---------------------------------------------------------------------
41
+ # Messages
42
+ # ---------------------------------------------------------------------
43
+
44
+ #
45
+ # Get a list of message names that this object receives.
46
+ #
47
+ def self.messages
48
+ return super + %w[inc dec]
49
+ end
50
+
51
+ #
52
+ # Increment the integer
53
+ #
54
+ def msg_inc
55
+ i = value + 1
56
+ set_value i
57
+ @engine.heap.it.set_to i
58
+ return i
59
+ end
60
+
61
+ #
62
+ # Decrement the integer
63
+ #
64
+ def msg_dec
65
+ i = value - 1
66
+ set_value i
67
+ @engine.heap.it.set_to i
68
+ return i
69
+ end
70
+
71
+ end
72
+ end
73
+ end