gloo 6.0.1 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/CLAUDE.md +9 -3
  3. data/README.md +39 -7
  4. data/docs/application.md +184 -0
  5. data/docs/getting_started.md +110 -0
  6. data/docs/iterators.md +294 -0
  7. data/docs/language_objects.md +190 -0
  8. data/docs/language_scripting.md +62 -0
  9. data/docs/language_syntax.md +334 -0
  10. data/docs/objects.md +77 -0
  11. data/docs/operators.md +62 -0
  12. data/docs/plugins.md +376 -0
  13. data/docs/verbs.md +64 -0
  14. data/docs/web_app.md +211 -0
  15. data/gloo.gemspec +3 -1
  16. data/lib/VERSION +1 -1
  17. data/lib/VERSION_NOTES +16 -0
  18. data/lib/gloo/app/engine.rb +17 -2
  19. data/lib/gloo/app/log.rb +5 -4
  20. data/lib/gloo/app/platform.rb +34 -2
  21. data/lib/gloo/app/prompt.rb +2 -1
  22. data/lib/gloo/app/settings.rb +25 -15
  23. data/lib/gloo/app/table.rb +7 -3
  24. data/lib/gloo/app/theme.rb +144 -0
  25. data/lib/gloo/core/gloo_system.rb +52 -1
  26. data/lib/gloo/core/invoker.rb +102 -0
  27. data/lib/gloo/core/parser.rb +48 -7
  28. data/lib/gloo/core/tokens.rb +81 -1
  29. data/lib/gloo/docs/doc_data.rb +160 -0
  30. data/lib/gloo/docs/help_shell.rb +332 -0
  31. data/lib/gloo/docs/markdown_renderer.rb +39 -0
  32. data/lib/gloo/expr/call.rb +54 -0
  33. data/lib/gloo/expr/expression.rb +3 -0
  34. data/lib/gloo/objs/basic/alias.rb +53 -0
  35. data/lib/gloo/objs/basic/boolean.rb +30 -0
  36. data/lib/gloo/objs/basic/container.rb +38 -0
  37. data/lib/gloo/objs/basic/decimal.rb +30 -0
  38. data/lib/gloo/objs/basic/integer.rb +58 -0
  39. data/lib/gloo/objs/basic/script.rb +31 -0
  40. data/lib/gloo/objs/basic/string.rb +31 -4
  41. data/lib/gloo/objs/basic/string_msgs.rb +212 -2
  42. data/lib/gloo/objs/basic/text.rb +30 -4
  43. data/lib/gloo/objs/basic/untyped.rb +21 -0
  44. data/lib/gloo/objs/ctrl/each.rb +63 -1
  45. data/lib/gloo/objs/ctrl/function.rb +86 -4
  46. data/lib/gloo/objs/ctrl/repeat.rb +41 -0
  47. data/lib/gloo/objs/dt/date.rb +43 -0
  48. data/lib/gloo/objs/dt/datetime.rb +50 -0
  49. data/lib/gloo/objs/dt/time.rb +43 -0
  50. data/lib/gloo/objs/str_utils/cipher.rb +59 -0
  51. data/lib/gloo/objs/str_utils/outline.rb +65 -1
  52. data/lib/gloo/objs/str_utils/password.rb +56 -0
  53. data/lib/gloo/objs/system/erb.rb +39 -0
  54. data/lib/gloo/objs/system/file_handle.rb +56 -0
  55. data/lib/gloo/objs/system/system.rb +29 -0
  56. data/lib/gloo/objs/web/http_get.rb +35 -0
  57. data/lib/gloo/objs/web/http_post.rb +33 -0
  58. data/lib/gloo/objs/web/json.rb +40 -0
  59. data/lib/gloo/objs/web/uri.rb +40 -0
  60. data/lib/gloo/shell/command_node.rb +39 -0
  61. data/lib/gloo/shell/context.rb +93 -0
  62. data/lib/gloo/shell/runner.rb +315 -0
  63. data/lib/gloo/verbs/break.rb +32 -0
  64. data/lib/gloo/verbs/check.rb +49 -0
  65. data/lib/gloo/verbs/cls.rb +18 -0
  66. data/lib/gloo/verbs/context.rb +47 -0
  67. data/lib/gloo/verbs/create.rb +42 -0
  68. data/lib/gloo/verbs/eval.rb +27 -0
  69. data/lib/gloo/verbs/execute.rb +27 -0
  70. data/lib/gloo/verbs/exists.rb +54 -2
  71. data/lib/gloo/verbs/files.rb +22 -0
  72. data/lib/gloo/verbs/help.rb +46 -178
  73. data/lib/gloo/verbs/if.rb +52 -0
  74. data/lib/gloo/verbs/invoke.rb +88 -33
  75. data/lib/gloo/verbs/list.rb +37 -4
  76. data/lib/gloo/verbs/load.rb +55 -2
  77. data/lib/gloo/verbs/log.rb +44 -0
  78. data/lib/gloo/verbs/move.rb +36 -1
  79. data/lib/gloo/verbs/put.rb +35 -0
  80. data/lib/gloo/verbs/quit.rb +19 -0
  81. data/lib/gloo/verbs/redirect.rb +52 -2
  82. data/lib/gloo/verbs/reload.rb +27 -0
  83. data/lib/gloo/verbs/run.rb +39 -0
  84. data/lib/gloo/verbs/save.rb +26 -0
  85. data/lib/gloo/verbs/show.rb +54 -0
  86. data/lib/gloo/verbs/tell.rb +32 -0
  87. data/lib/gloo/verbs/throw.rb +29 -0
  88. data/lib/gloo/verbs/unless.rb +50 -0
  89. data/lib/gloo/verbs/unload.rb +23 -0
  90. data/lib/gloo/verbs/version.rb +37 -3
  91. data/lib/gloo/verbs/wait.rb +26 -0
  92. data/test.gloo/objs/string.test.gloo +54 -0
  93. data/test.gloo/verbs/invoke.test.gloo +73 -0
  94. metadata +26 -10
  95. data/.DS_Store +0 -0
  96. data/.travis.yml +0 -5
@@ -0,0 +1,190 @@
1
+ # Language, Objects
2
+
3
+ **Contents**
4
+
5
+ - Object Naming
6
+ - Keywords
7
+ - Literals
8
+ - Value Conversion
9
+
10
+ ## Object Naming
11
+
12
+ Object names are single words (no spaces) and conform to the following:
13
+
14
+ - Spaces in names are not allowed.
15
+ - Names should be unique within their context.
16
+ - Note that there is no technical restriction. Multiple objects with the same name in the same context can exist, but there's no way to reference objects past the first one with the given name.
17
+ - Names can be capitalized or lower case.
18
+ - But names with different cases are not treated as unique.
19
+ - Names can contain numbers and special characters.
20
+
21
+ ```gloo
22
+ #
23
+ # Example of object naming.
24
+ #
25
+ # NOTE that the second 'a' and the 'A' objects are not reachable.
26
+ # 'naming.a' will always reach the 'First A' string.
27
+ #
28
+ naming [container] :
29
+ on_load [script] :
30
+ show naming.msg!$%
31
+ show naming.a
32
+ show naming.1
33
+ msg!$% [string] : Naming stuff
34
+ a [string] : First A
35
+ a [string] : Second A is not reachable
36
+ A [string] : Capital A is not reachable
37
+ 1 [string] : One
38
+ ```
39
+
40
+ See also: Pathname.
41
+
42
+ ## Keywords
43
+
44
+ Gloo doesn't reserve words the way many languages do. A verb keyword like `put` or an object type name like `string` can also be used as an object name — there's no parser conflict, because verbs are only looked up as the first word of a statement, and object type names are only looked up where a type is expected (inside the `[ ]` on a declaration). Everywhere else, the word is just a pathname segment (see Object Naming, above).
45
+
46
+ That said, gloo's own vocabulary — words that already mean something built-in — comes from two sources:
47
+
48
+ - Verb keywords, and their shortcuts (see Verbs) — `put`, `show`, `run`, `tell`, and the rest.
49
+ - Object type names, and their shortcuts (see Objects) — `string`, `container`, `integer`, and the rest.
50
+
51
+ Both lists grow as core libraries and extensions load — `load lib {name}` and `load ext {name}` can add new verbs and object types at runtime, so the full set isn't fixed. Use the in-app help (see Application, Help) for the live list of whatever's currently loaded: enter `help` (or `?`), then `verbs` or `objects`.
52
+
53
+ See also: Verbs, Objects.
54
+
55
+ ## Literals
56
+
57
+ Literals are values inline in a script command.
58
+
59
+ The following rules apply to literal values:
60
+
61
+ - Strings
62
+ - Can be delimited by single or double quotes. (`"` or `'`)
63
+ - Numbers
64
+ - Integer and decimal numbers need no delimiters.
65
+ - To refer to a decimal with no fractional value, include `.0` to indicate a decimal value.
66
+ - Booleans
67
+ - Can be `TRUE` or `FALSE`
68
+ - Note that the text is case insensitive.
69
+
70
+ ```gloo
71
+ #
72
+ # Examples of literal values.
73
+ #
74
+
75
+ literal [can] :
76
+
77
+ s [string] :
78
+ i [integer] :
79
+ d [decimal] :
80
+ b [boolean] :
81
+
82
+ #
83
+ # Use Literals to assign values
84
+ #
85
+ on_load [script] :
86
+
87
+ # String literals
88
+ put 'Hello world.' into ^.s
89
+ show ^.s
90
+ put "You're Awesome!" into ^.s
91
+ show ^.s
92
+
93
+ # Number literals
94
+ put 1 into ^.i
95
+ show ^.i
96
+ put 3.12 into ^.d
97
+ show ^.d
98
+
99
+ # Boolean literals
100
+ # Boolean literals are case insensitive
101
+ put TRUE into ^.b
102
+ show ^.b
103
+ put false into ^.b
104
+ show ^.b
105
+ ```
106
+
107
+ See also: Put, Show, String, Boolean, Integer, Decimal, Value Conversion.
108
+
109
+ ## Value Conversion
110
+
111
+ When putting an object or literal value into another object, gloo will attempt to convert the value to the target type.
112
+
113
+ Here are some of the value conversions that gloo will attempt:
114
+
115
+ - string to integer
116
+ - additional text is discarded
117
+ - `put '1 one' into x` => 1
118
+ - integer to string
119
+ - simple to-string conversion
120
+ - string to decimal
121
+ - additional text is discarded
122
+ - `put '3.25 and more…' into x` => 3.25
123
+ - decimal to string
124
+ - simple to-string conversion
125
+ - decimal to integer
126
+ - drops everything after the decimal point
127
+ - `put 1.23 into x` => 1
128
+ - integer to decimal
129
+ - decimal with integer value
130
+ - `put 1 into d` => 1.0
131
+ - string to boolean
132
+ - if the string is (trimmed, case-insensitive) 'true' or 't' then the boolean is true; 'false' or 'f' is false; anything else is false
133
+ - `put 'true' into bool` => true
134
+ - boolean to string
135
+ - simple to-string conversion: 'true' or 'false'
136
+ - integer to boolean
137
+ - 0 => false, otherwise true
138
+ - `put 1 into bool` => true
139
+ - boolean to integer
140
+ - true => 1, false => 0
141
+ - string to date
142
+ - uses Chronic lib to convert text to date
143
+ - `put '7/11' into dt` => 2024.07.11
144
+ - date to string
145
+ - convert date to string in default format
146
+ - string to time
147
+ - uses Chronic lib to convert text to time
148
+ - `put 'now' into time` => 01:24:55 pm
149
+ - time to string
150
+ - convert time to string in default format
151
+ - string to datetime
152
+ - uses Chronic lib to convert text to datetime
153
+ - `put 'now' into dt` => 2024.07.11 01:21:39 pm
154
+ - datetime to string
155
+ - convert datetime to string in default format
156
+
157
+ ```gloo
158
+ #
159
+ # Examples of value conversions.
160
+ #
161
+
162
+ convert [can] :
163
+
164
+ i [integer] : 1
165
+ d [decimal] : 7.75
166
+ s [string] : "hello"
167
+ b [boolean] : true
168
+ date [date] : "2024-07-11"
169
+ time [time] : "13:45:00"
170
+ dt [datetime] : "2024-07-11 13:45:00"
171
+
172
+ #
173
+ # Do some value conversions.
174
+ #
175
+ on_load [script] :
176
+
177
+ # String to integer
178
+ put '3 third time' into ^.i
179
+ show ^.i
180
+
181
+ # String to decimal
182
+ put '3.12 more' into ^.d
183
+ show ^.d
184
+
185
+ # String to date
186
+ put 'now' into ^.dt
187
+ show ^.dt
188
+ ```
189
+
190
+ See also: Literals.
@@ -0,0 +1,62 @@
1
+ # Language, Scripting
2
+
3
+ **Contents**
4
+
5
+ - Gloo Script Files
6
+ - Gloo Constants
7
+ - Line Continuation
8
+
9
+ ## Gloo Script Files
10
+
11
+ Gloo scripts are stored in regular text files with the `.gloo` extension.
12
+
13
+ Conventions:
14
+
15
+ - Script files are small and composable.
16
+ - Each file contains a single root level object.
17
+ - There is no system requirement that a file contains only a single object. There can be more than one.
18
+ - The single-root-object convention means that object hierarchy can better align with files in folders.
19
+ - The root level object has the same name as the file.
20
+
21
+ ```gloo
22
+ #
23
+ # Example of gloo script file.
24
+ #
25
+ hello [can] :
26
+ on_load [script] : show 'hello world'
27
+ ```
28
+
29
+ ## Gloo Constants
30
+
31
+ There is no gloo language construct for constants. They are simply objects. But by convention, constants are named in all caps. They might be in a container or at the root object level.
32
+
33
+ ```gloo
34
+ #
35
+ # Example of a constant in gloo.
36
+ #
37
+ constants [can] :
38
+
39
+ MSG [string] : Hello World!
40
+
41
+ on_load [script] :
42
+ show ^.MSG
43
+ ```
44
+
45
+ ## Line Continuation
46
+
47
+ In gloo scripting, a line continuation is done by ending a line with a backslash (`\`). Logical lines can be split across multiple physical lines of text in scripts. A line break is otherwise an indication of a new statement.
48
+
49
+ ```gloo
50
+ #
51
+ # Example of a continuation character in gloo scripts.
52
+ #
53
+
54
+ continuation [can] :
55
+
56
+ one [string] : Hello
57
+ two [string] : World!
58
+
59
+ on_load [script] :
60
+ show continuation.one and \
61
+ ' ' and continuation.two
62
+ ```
@@ -0,0 +1,334 @@
1
+ # Language, Syntax
2
+
3
+ **Contents**
4
+
5
+ - Color
6
+ - Errors
7
+ - Events
8
+ - Function Calls
9
+ - Gloo System Objects
10
+ - Here
11
+ - It
12
+ - Operators
13
+ - Pathname
14
+
15
+ ## Color
16
+
17
+ The following colors can be used by the `show` verb to display colored text:
18
+
19
+ ```gloo
20
+ red
21
+ blue
22
+ green
23
+ white
24
+ black
25
+ yellow
26
+ ```
27
+
28
+ These are the common ones, but any color name from the `colorize` gem works too (e.g. `cyan`, `magenta`, or a `light_` variant of any of the above).
29
+
30
+ The color names are considered as virtual objects but may also be referenced in variables. See the example below.
31
+
32
+ ```gloo
33
+ #
34
+ # Show multiple messages in color
35
+ #
36
+ colors [can] :
37
+ var [string] : red
38
+ on_load [script] :
39
+ show "red" (colors.var)
40
+ show "blue" (blue)
41
+ show "green" (green)
42
+ ```
43
+
44
+ See also: Show.
45
+
46
+ ## Errors
47
+
48
+ Gloo has a special `error` variable that's not part of the normal object heap. The error will be empty most of the time, but if a command results in an error, this variable will hold the error message until the next command is executed. The error is a string and can be accessed by simply referring to the path-name `error`.
49
+
50
+ To see the last error:
51
+
52
+ ```
53
+ > show error
54
+ ```
55
+
56
+ To run a command that generates an error:
57
+
58
+ ```
59
+ > put 3 into
60
+ Target (into) missing!
61
+ ```
62
+
63
+ Then, showing the error:
64
+
65
+ ```
66
+ > show error
67
+ Target (into) missing!
68
+ ```
69
+
70
+ But, as mentioned, the next command will clear out the last error. If you need to keep track of the result of a command, you should put the error into another object.
71
+
72
+ ```
73
+ > create err as string
74
+ > put 3 into
75
+ > put error into err
76
+ ```
77
+
78
+ See also: Pathname.
79
+
80
+ ## Events
81
+
82
+ Scripts can be written to be triggered by events. The current list is as follows, but it is expected that the list of events will grow.
83
+
84
+ The following events are application and file-level events:
85
+
86
+ - `on_load` — run when an object loads
87
+ - `on_unload` — run when an object receives an unload message
88
+ - `on_quit` — event triggered when gloo is quitting
89
+ - `on_save` — when an object is saved, this event is triggered
90
+ - `on_reload` — event triggered when an object receives message to reload
91
+ - `on_error` — event triggered when there is an error in the application
92
+
93
+ Some objects also have events that are triggered as part of their lifecycle. Here are some examples:
94
+
95
+ - function — `on_invoke`, `after_invoke`
96
+ - server — `on_start`, `on_stop`
97
+ - page — `on_prerender`, `on_render`, `after_render`
98
+ - partial — `on_render`, `after_render`
99
+
100
+ ```gloo
101
+ #
102
+ # Show a message when a file is loaded:
103
+ #
104
+ start [container] :
105
+ on_load [script] : show "Welcome back!" (white)
106
+
107
+
108
+ #
109
+ # Show a message when a file unloaded:
110
+ #
111
+ done [container] :
112
+ on_unload [script] : show "See ya soon!" (white)
113
+
114
+
115
+ #
116
+ # Show a message when gloo is quitting:
117
+ #
118
+ quitting [container] :
119
+ on_quit [script] : show "Gloo is done for now." (white)
120
+
121
+
122
+ #
123
+ # Show a message when an object is going to be saved:
124
+ #
125
+ on_save [script] :
126
+ show 'This object file is going to saved now.' (yellow)
127
+
128
+
129
+ #
130
+ # Show a message when an object is giong to be re-loaded:
131
+ #
132
+ on_reload [script] :
133
+ show "The object is reloading now."
134
+
135
+ #
136
+ # Global Error Handler.
137
+ # Include the data container for the error data.
138
+ # The data is populated by the application on error event.
139
+ #
140
+ on_error [script] :
141
+ tell audit_error.write to run
142
+
143
+ error_data [can] :
144
+ message [string] :
145
+ backtrace [string] :
146
+ ```
147
+
148
+ See also: Load, Reload, Unload, Save, Quit.
149
+
150
+ ## Function Calls
151
+
152
+ The `invoke` verb (shortcut `~>`) calls a function object (`[ƒ]`) as a standalone command, space-separated params:
153
+
154
+ ```gloo
155
+ invoke functions.add 3 4
156
+ show it
157
+ ```
158
+
159
+ `invoke( ... )` and `~>( ... )` are the inline forms of the same thing — usable anywhere an expression is evaluated (`show`, `put ... into`, `if`, `unless`, `eval`, and more), not just as a standalone command:
160
+
161
+ ```gloo
162
+ show invoke( functions.add 3 4 )
163
+ put ~>( functions.add 3 4 ) into total
164
+ show "Total: " + invoke( functions.add 3 4 )
165
+ if invoke( checks.is_ready ) then show 'ready'
166
+ ```
167
+
168
+ `invoke(...)` and `~>(...)` are exactly equivalent — just the full keyword and its shortcut, same as the standalone verb. Params stay space-separated inside the parens; each one is evaluated as a single token (a literal or object reference), same as the standalone verb — not a multi-token sub-expression, so `invoke( f 3+4 )` won't parse `3+4` as one param.
169
+
170
+ The parens must immediately follow the keyword with no space (`invoke(`, not `invoke (`) — that's what tells gloo it's a function call rather than `show`'s unrelated trailing `(color)` syntax, which always has a space before the paren.
171
+
172
+ See also: Color.
173
+
174
+ ## Gloo System Objects
175
+
176
+ The gloo system objects are virtual objects. That is, they can be accessed like other objects, but the values are set by the system. The values cannot be updated. The other difference is that the virtual objects do not show up in the object heap.
177
+
178
+ The gloo objects can be accessed through the `gloo` root level virtual object designation. There is also a shortcut for the virtual object path: `$`. For example, to see the current user:
179
+
180
+ ```
181
+ > show gloo.user
182
+ ```
183
+
184
+ Or:
185
+
186
+ ```
187
+ > show $.user
188
+ ```
189
+
190
+ Some objects include an `_` to separate words. As an alternative, a `.` can be used instead. The following commands are treated as identical:
191
+
192
+ ```
193
+ > show gloo.working_dir
194
+ > show gloo.working.dir
195
+ > show $.working_dir
196
+ > show $.working.dir
197
+ ```
198
+
199
+ ```
200
+ APP
201
+ gloo.app # Path of the running app. (Same as gloo.gloo_projects)
202
+
203
+ IDENTITY
204
+ gloo.hostname # Get the system hostname.
205
+ gloo.user # Get the logged in User.
206
+
207
+ SPECIAL CHARS
208
+ gloo.line # A carriage return (line feed) character.
209
+
210
+ FILE SYSTEM
211
+ gloo.user_home # Get the user's home directory.
212
+ gloo.working_dir # Get the working directory.
213
+ gloo.gloo_home # Get the gloo home directory
214
+ gloo.gloo_config # Get the gloo configuration directory
215
+ gloo.gloo_projects # Get the gloo projects directory
216
+ gloo.gloo_log # Get the gloo logging directory
217
+
218
+ SCREEN
219
+ gloo.screen_lines # Get the number of lines on screen.
220
+ gloo.screen_cols # Get the number of columns on screen.
221
+
222
+ PLATFORM
223
+ gloo.platform_cpu # Get the platform CPU
224
+ gloo.platform_os # Get the platform Operating System
225
+ gloo.platform_version # Get the platform version
226
+ gloo.platform_windows? # Is the platform Windows?
227
+ gloo.platform_unix? # Is the platform Unix?
228
+ gloo.platform_linux? # Is the platform Linux?
229
+ gloo.platform_mac? # Is the platform Mac?
230
+ gloo.platform_wsl? # Is the platform WSL (Windows Subsystem for Linux)?
231
+ ```
232
+
233
+ See also: Pathname. The file-system subset of these objects is also referenced in Application > The Gloo Home Directory.
234
+
235
+ ## Here
236
+
237
+ Gloo scripts can use relative referencing to access objects without specifying the full path. This relative referencing is referred to as the "here" operator, which is a single caret (`^`) character.
238
+
239
+ Using two carets together (`^^`) means to go up a level — that is, go to the parent container to find the object. Three carets, `^^^`, says to go up yet another level in the object hierarchy.
240
+
241
+ In the following script, the here reference is used several times:
242
+
243
+ ```gloo
244
+ #
245
+ # Use here reference.
246
+ #
247
+ here [can] :
248
+ s [str] : local string
249
+ on_load [script] : show ^.s
250
+ a [can] :
251
+ s [str] : A string
252
+ b [can] :
253
+ s [str] : B string
254
+ on_load [script] :
255
+ show ^.s
256
+ show ^^.s
257
+ ```
258
+
259
+ A single use of `^` means: refer to an object at the same level as the running script. It tells the interpreter to "look here" for the object.
260
+
261
+ Use of two `^^` here references means to go up a level, and so forth.
262
+
263
+ See also: Pathname.
264
+
265
+ ## It
266
+
267
+ `it` is a special virtual object. `it` contains the value of the last expression or command run. Not all commands result in a change to the value of `it`.
268
+
269
+ Get the value of an expression and store it somewhere for later use:
270
+
271
+ ```gloo
272
+ #
273
+ # Example of usage of 'it'.
274
+ #
275
+ example [can] :
276
+ result [int] :
277
+ on_load [script] :
278
+ show 3 + 4
279
+ put it into ^.result
280
+ show ^.result
281
+ ```
282
+
283
+ Running this script will show `7` twice. The first time will be the result of the addition. The second time will be showing the result object.
284
+
285
+ See also: Pathname.
286
+
287
+ ## Operators
288
+
289
+ Operators have their own dedicated page — see the Operators page.
290
+
291
+ ## Pathname
292
+
293
+ All gloo object data and scripts are stored in a heap of objects, or just "the heap." The heap is hierarchical, with some objects having children objects. To reference an object, we use a "pathname." The pathname starts with the root level object, then has a period, `.`, then the child object name, and so forth. `a.b.c` refers to the `c` object in the `b` container, which is in the `a` container.
294
+
295
+ ### Root & Context
296
+
297
+ The word "root" is not needed when referring to objects. In some special cases, "root" can be used to point to the first level of the object heap. One such use would be with the "context" verb.
298
+
299
+ The pathname will start from the root container. When context has been set, the pathname can start from the context container by use of the `@.` prefix. For example:
300
+
301
+ ```gloo
302
+ context [container] :
303
+ sub [container] :
304
+ msg [string] : Hello Gloo World!
305
+ on_load [script] :
306
+ @ context.sub
307
+ show @.msg
308
+ @ root
309
+ ```
310
+
311
+ Full pathnames can be used when context has been set.
312
+
313
+ ### Exceptional Cases
314
+
315
+ The following are also exceptional pathname cases:
316
+
317
+ - Here
318
+ - It
319
+ - Errors
320
+ - Gloo System Objects
321
+
322
+ Here is an example of objects and a pathname reference to an object within the hierarchy:
323
+
324
+ ```gloo
325
+ #
326
+ # Hierarchical containers.
327
+ #
328
+ a [can] :
329
+ b [can] :
330
+ c [string] : Hello World
331
+ on_load [script] : show a.b.c
332
+ ```
333
+
334
+ See also: Context, Object Naming.
data/docs/objects.md ADDED
@@ -0,0 +1,77 @@
1
+ # Objects
2
+
3
+ Everything in gloo is an object. Strings, numbers, containers, scripts, functions, dates — even the folder-like structures that hold your code — are all objects, and they're all accessed and manipulated the same way: by sending them messages.
4
+
5
+ Gloo ships with a large set of built-in object types, and core libraries and extensions can add more. This page doesn't try to cover them all — it walks through three common ones to get a feel for how objects work. For the complete list of object types, and every message each one supports, use the in-app help: enter `help` (or `?`), then `objects` to list them all, or `object {name}` for detail on one (see Application, Help).
6
+
7
+ **Contents**
8
+
9
+ - String
10
+ - Container
11
+ - Integer
12
+
13
+ ## String
14
+
15
+ A string holds text. Beyond just storing a value, a string object responds to messages that transform or inspect it:
16
+
17
+ ```gloo
18
+ s [can] :
19
+ msg [string] : Hello World!
20
+ on_load [script] :
21
+ show s.msg
22
+ tell s.msg to up
23
+ show s.msg
24
+ tell s.msg to size
25
+ show it
26
+ ```
27
+
28
+ Sending `up` to the string converts it to uppercase, in place. Sending `size` puts the character count into `it`. There are messages for lowercasing, counting words and lines, checking prefixes/suffixes, encoding, and generating random strings (UUIDs, hex, alphanumeric) — see the in-app help for the full list.
29
+
30
+ ## Container
31
+
32
+ A container holds other objects — it's the closest thing gloo has to a folder, a hash, or a struct. Any object nested inside a container is reachable through a dotted pathname:
33
+
34
+ ```gloo
35
+ can [can] :
36
+ data [can] :
37
+ 1 : one
38
+ 2 : two
39
+ 3 : three
40
+ on_load [script] :
41
+ tell can.data to count
42
+ show it
43
+ ```
44
+
45
+ `can.data` is itself a container holding three children; `count` puts the number of children into `it`. Because containers can nest arbitrarily, this is how gloo builds up everything from simple config blocks to entire applications.
46
+
47
+ ## Integer
48
+
49
+ An integer holds a numeric value and responds to a handful of convenience messages:
50
+
51
+ ```gloo
52
+ #
53
+ # Integer object.
54
+ #
55
+ i [can] :
56
+ x [integer] : 0
57
+ on_load [script] :
58
+ show i.x
59
+ tell i.x to inc
60
+ show i.x
61
+ put i.x * 10 into i.x
62
+ show i.x
63
+
64
+ # Show a random number
65
+ tell ^.x to randomize
66
+ show 'Random number (up to 100 by default): ' + ^.x
67
+
68
+ tell ^.x to randomize(6)
69
+ tell ^.x to inc
70
+ show '6-sided dice: ' + ^.x
71
+ ```
72
+
73
+ `inc`/`dec` step the value by one; `randomize` sets it to a random number in a range (0 by default, or up to a given maximum — handy for things like rolling a die).
74
+
75
+ ---
76
+
77
+ These three barely scratch the surface — decimals, booleans, dates, files, functions, and many more object types are all documented in-app. Enter `help` (or `?`), then `objects` to browse them. (This page itself is also viewable in-app: `help> doc objects`.)