gloo 6.0 → 6.1.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.
- checksums.yaml +4 -4
- data/CLAUDE.md +9 -3
- data/README.md +38 -7
- data/docs/application.md +164 -0
- data/docs/getting_started.md +112 -0
- data/docs/iterators.md +294 -0
- data/docs/language_objects.md +190 -0
- data/docs/language_scripting.md +62 -0
- data/docs/language_syntax.md +307 -0
- data/docs/objects.md +77 -0
- data/docs/operators.md +62 -0
- data/docs/plugins.md +54 -0
- data/docs/verbs.md +64 -0
- data/gloo.gemspec +5 -3
- data/lib/VERSION +1 -1
- data/lib/VERSION_NOTES +14 -0
- data/lib/gloo/app/platform.rb +29 -2
- data/lib/gloo/app/settings.rb +1 -1
- data/lib/gloo/core/gloo_system.rb +52 -1
- data/lib/gloo/docs/doc_data.rb +160 -0
- data/lib/gloo/docs/help_shell.rb +285 -0
- data/lib/gloo/docs/markdown_renderer.rb +39 -0
- data/lib/gloo/objs/basic/alias.rb +53 -0
- data/lib/gloo/objs/basic/boolean.rb +30 -0
- data/lib/gloo/objs/basic/container.rb +38 -0
- data/lib/gloo/objs/basic/decimal.rb +30 -0
- data/lib/gloo/objs/basic/integer.rb +58 -0
- data/lib/gloo/objs/basic/script.rb +31 -0
- data/lib/gloo/objs/basic/string.rb +51 -4
- data/lib/gloo/objs/basic/string_msgs.rb +20 -0
- data/lib/gloo/objs/basic/text.rb +51 -4
- data/lib/gloo/objs/basic/untyped.rb +21 -0
- data/lib/gloo/objs/ctrl/each.rb +63 -1
- data/lib/gloo/objs/ctrl/function.rb +69 -0
- data/lib/gloo/objs/ctrl/repeat.rb +41 -0
- data/lib/gloo/objs/dt/date.rb +43 -0
- data/lib/gloo/objs/dt/datetime.rb +50 -0
- data/lib/gloo/objs/dt/time.rb +43 -0
- data/lib/gloo/objs/str_utils/cipher.rb +59 -0
- data/lib/gloo/objs/str_utils/outline.rb +65 -1
- data/lib/gloo/objs/str_utils/password.rb +56 -0
- data/lib/gloo/objs/system/erb.rb +39 -0
- data/lib/gloo/objs/system/file_handle.rb +56 -0
- data/lib/gloo/objs/system/system.rb +29 -0
- data/lib/gloo/objs/web/http_get.rb +35 -0
- data/lib/gloo/objs/web/http_post.rb +33 -0
- data/lib/gloo/objs/web/json.rb +40 -0
- data/lib/gloo/objs/web/uri.rb +40 -0
- data/lib/gloo/shell/command_node.rb +39 -0
- data/lib/gloo/shell/context.rb +93 -0
- data/lib/gloo/shell/runner.rb +315 -0
- data/lib/gloo/verbs/break.rb +32 -0
- data/lib/gloo/verbs/check.rb +49 -0
- data/lib/gloo/verbs/cls.rb +18 -0
- data/lib/gloo/verbs/context.rb +47 -0
- data/lib/gloo/verbs/create.rb +42 -0
- data/lib/gloo/verbs/eval.rb +27 -0
- data/lib/gloo/verbs/execute.rb +27 -0
- data/lib/gloo/verbs/exists.rb +54 -2
- data/lib/gloo/verbs/files.rb +22 -0
- data/lib/gloo/verbs/help.rb +43 -178
- data/lib/gloo/verbs/if.rb +52 -0
- data/lib/gloo/verbs/invoke.rb +62 -0
- data/lib/gloo/verbs/list.rb +32 -0
- data/lib/gloo/verbs/load.rb +55 -2
- data/lib/gloo/verbs/log.rb +44 -0
- data/lib/gloo/verbs/move.rb +36 -1
- data/lib/gloo/verbs/put.rb +35 -0
- data/lib/gloo/verbs/quit.rb +19 -0
- data/lib/gloo/verbs/redirect.rb +52 -2
- data/lib/gloo/verbs/reload.rb +27 -0
- data/lib/gloo/verbs/run.rb +39 -0
- data/lib/gloo/verbs/save.rb +26 -0
- data/lib/gloo/verbs/show.rb +54 -0
- data/lib/gloo/verbs/tell.rb +32 -0
- data/lib/gloo/verbs/throw.rb +29 -0
- data/lib/gloo/verbs/unless.rb +50 -0
- data/lib/gloo/verbs/unload.rb +23 -0
- data/lib/gloo/verbs/version.rb +37 -3
- data/lib/gloo/verbs/wait.rb +26 -0
- metadata +28 -20
|
@@ -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 ~ 'true' then the boolean is true, otherwise 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,307 @@
|
|
|
1
|
+
# Language, Syntax
|
|
2
|
+
|
|
3
|
+
**Contents**
|
|
4
|
+
|
|
5
|
+
- Color
|
|
6
|
+
- Errors
|
|
7
|
+
- Events
|
|
8
|
+
- Gloo System Objects
|
|
9
|
+
- Here
|
|
10
|
+
- It
|
|
11
|
+
- Operators
|
|
12
|
+
- Pathname
|
|
13
|
+
|
|
14
|
+
## Color
|
|
15
|
+
|
|
16
|
+
The following colors can be used by the `show` verb to display colored text:
|
|
17
|
+
|
|
18
|
+
```gloo
|
|
19
|
+
red
|
|
20
|
+
blue
|
|
21
|
+
green
|
|
22
|
+
white
|
|
23
|
+
black
|
|
24
|
+
yellow
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The color names are considered as virtual objects but may also be referenced in variables. See the example below.
|
|
28
|
+
|
|
29
|
+
```gloo
|
|
30
|
+
#
|
|
31
|
+
# Show multiple messages in color
|
|
32
|
+
#
|
|
33
|
+
colors [can] :
|
|
34
|
+
var [string] : red
|
|
35
|
+
on_load [script] :
|
|
36
|
+
show "red" (colors.var)
|
|
37
|
+
show "blue" (blue)
|
|
38
|
+
show "green" (green)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
See also: Show.
|
|
42
|
+
|
|
43
|
+
## Errors
|
|
44
|
+
|
|
45
|
+
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`.
|
|
46
|
+
|
|
47
|
+
To see the last error:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
> show error
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
To run a command that generates an error:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
> put 3 into
|
|
57
|
+
'put' must include 'into' target
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Then, showing the error:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
> show error
|
|
64
|
+
'put' must include 'into' target
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
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.
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
> create err as string
|
|
71
|
+
> put 3 into
|
|
72
|
+
> put error into err
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
See also: Pathname.
|
|
76
|
+
|
|
77
|
+
## Events
|
|
78
|
+
|
|
79
|
+
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.
|
|
80
|
+
|
|
81
|
+
The following events are application and file-level events:
|
|
82
|
+
|
|
83
|
+
- `on_load` — run when an object loads
|
|
84
|
+
- `on_unload` — run when an object receives an unload message
|
|
85
|
+
- `on_quit` — event triggered when gloo is quitting
|
|
86
|
+
- `on_save` — when an object is saved, this event is triggered
|
|
87
|
+
- `on_reload` — event triggered when an object receives message to reload
|
|
88
|
+
- `on_error` — event triggered when there is an error in the application
|
|
89
|
+
|
|
90
|
+
Some objects also have events that are triggered as part of their lifecycle. Here are some examples:
|
|
91
|
+
|
|
92
|
+
- function — `on_invoke`, `after_invoke`
|
|
93
|
+
- server — `on_start`, `on_stop`
|
|
94
|
+
- page — `on_prerender`, `on_render`, `after_render`
|
|
95
|
+
- partial — `on_render`, `after_render`
|
|
96
|
+
|
|
97
|
+
```gloo
|
|
98
|
+
#
|
|
99
|
+
# Show a message when a file is loaded:
|
|
100
|
+
#
|
|
101
|
+
start [container] :
|
|
102
|
+
on_load [script] : show "Welcome back!" (white)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
#
|
|
106
|
+
# Show a message when a file unloaded:
|
|
107
|
+
#
|
|
108
|
+
done [container] :
|
|
109
|
+
on_unload [script] : show "See ya soon!" (white)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
#
|
|
113
|
+
# Show a message when gloo is quitting:
|
|
114
|
+
#
|
|
115
|
+
quitting [container] :
|
|
116
|
+
on_quit [script] : show "Gloo is done for now." (white)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
#
|
|
120
|
+
# Show a message when an object is going to be saved:
|
|
121
|
+
#
|
|
122
|
+
on_save [script] :
|
|
123
|
+
show 'This object file is going to saved now.' (yellow)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
#
|
|
127
|
+
# Show a message when an object is giong to be re-loaded:
|
|
128
|
+
#
|
|
129
|
+
on_reload [script] :
|
|
130
|
+
show "The object is reloading now."
|
|
131
|
+
|
|
132
|
+
#
|
|
133
|
+
# Global Error Handler.
|
|
134
|
+
# Include the data container for the error data.
|
|
135
|
+
# The data is populated by the application on error event.
|
|
136
|
+
#
|
|
137
|
+
on_error [script] :
|
|
138
|
+
tell audit_error.write to run
|
|
139
|
+
|
|
140
|
+
error_data [can] :
|
|
141
|
+
message [string] :
|
|
142
|
+
backtrace [string] :
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
See also: Load, Reload, Unload, Save, Quit.
|
|
146
|
+
|
|
147
|
+
## Gloo System Objects
|
|
148
|
+
|
|
149
|
+
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.
|
|
150
|
+
|
|
151
|
+
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:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
> show gloo.user
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Or:
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
> show $.user
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Some objects include an `_` to separate words. As an alternative, a `.` can be used instead. The following commands are treated as identical:
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
> show gloo.working_dir
|
|
167
|
+
> show gloo.working.dir
|
|
168
|
+
> show $.working_dir
|
|
169
|
+
> show $.working.dir
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
APP
|
|
174
|
+
gloo.app # Path of the running app. (Same as gloo.gloo_projects)
|
|
175
|
+
|
|
176
|
+
IDENTITY
|
|
177
|
+
gloo.hostname # Get the system hostname.
|
|
178
|
+
gloo.user # Get the logged in User.
|
|
179
|
+
|
|
180
|
+
SPECIAL CHARS
|
|
181
|
+
gloo.line # A carriage return (line feed) character.
|
|
182
|
+
|
|
183
|
+
FILE SYSTEM
|
|
184
|
+
gloo.user_home # Get the user's home directory.
|
|
185
|
+
gloo.working_dir # Get the working directory.
|
|
186
|
+
gloo.gloo_home # Get the gloo home directory
|
|
187
|
+
gloo.gloo_config # Get the gloo configuration directory
|
|
188
|
+
gloo.gloo_projects # Get the gloo projects directory
|
|
189
|
+
gloo.gloo_log # Get the gloo logging directory
|
|
190
|
+
|
|
191
|
+
SCREEN
|
|
192
|
+
gloo.screen_lines # Get the number of lines on screen.
|
|
193
|
+
gloo.screen_cols # Get the number of columns on screen.
|
|
194
|
+
|
|
195
|
+
PLATFORM
|
|
196
|
+
gloo.platform_cpu # Get the platform CPU
|
|
197
|
+
gloo.platform_os # Get the platform Operating System
|
|
198
|
+
gloo.platform_version # Get the platform version
|
|
199
|
+
gloo.platform_windows? # Is the platform Windows?
|
|
200
|
+
gloo.platform_unix? # Is the platform Unix?
|
|
201
|
+
gloo.platform_linux? # Is the platform Linux?
|
|
202
|
+
gloo.platform_mac? # Is the platform Mac?
|
|
203
|
+
gloo.platform_wsl? # Is the platform WSL (Windows Subsystem for Linux)?
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
See also: Pathname. The file-system subset of these objects is also referenced in Application > The Gloo Home Directory.
|
|
207
|
+
|
|
208
|
+
## Here
|
|
209
|
+
|
|
210
|
+
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.
|
|
211
|
+
|
|
212
|
+
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.
|
|
213
|
+
|
|
214
|
+
In the following script, the here reference is used several times:
|
|
215
|
+
|
|
216
|
+
```gloo
|
|
217
|
+
#
|
|
218
|
+
# Use here reference.
|
|
219
|
+
#
|
|
220
|
+
here [can] :
|
|
221
|
+
s [str] : local string
|
|
222
|
+
on_load [script] : show ^.s
|
|
223
|
+
a [can] :
|
|
224
|
+
s [str] : A string
|
|
225
|
+
b [can] :
|
|
226
|
+
s [str] : B string
|
|
227
|
+
on_load [script] :
|
|
228
|
+
show ^.s
|
|
229
|
+
show ^^.s
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
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.
|
|
233
|
+
|
|
234
|
+
Use of two `^^` here references means to go up a level, and so forth.
|
|
235
|
+
|
|
236
|
+
See also: Pathname.
|
|
237
|
+
|
|
238
|
+
## It
|
|
239
|
+
|
|
240
|
+
`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`.
|
|
241
|
+
|
|
242
|
+
Get the value of an expression and store it somewhere for later use:
|
|
243
|
+
|
|
244
|
+
```gloo
|
|
245
|
+
#
|
|
246
|
+
# Example of usage of 'it'.
|
|
247
|
+
#
|
|
248
|
+
example [can] :
|
|
249
|
+
result [int] :
|
|
250
|
+
on_load [script] :
|
|
251
|
+
show 3 + 4
|
|
252
|
+
put it into ^.result
|
|
253
|
+
show ^.result
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
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.
|
|
257
|
+
|
|
258
|
+
See also: Pathname.
|
|
259
|
+
|
|
260
|
+
## Operators
|
|
261
|
+
|
|
262
|
+
Operators have their own dedicated page — see the Operators page.
|
|
263
|
+
|
|
264
|
+
## Pathname
|
|
265
|
+
|
|
266
|
+
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.
|
|
267
|
+
|
|
268
|
+
### Root & Context
|
|
269
|
+
|
|
270
|
+
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.
|
|
271
|
+
|
|
272
|
+
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:
|
|
273
|
+
|
|
274
|
+
```gloo
|
|
275
|
+
context [container] :
|
|
276
|
+
sub [container] :
|
|
277
|
+
msg [string] : Hello Gloo World!
|
|
278
|
+
on_load [script] :
|
|
279
|
+
@ context.sub
|
|
280
|
+
show @.msg
|
|
281
|
+
@ root
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Full pathnames can be used when context has been set.
|
|
285
|
+
|
|
286
|
+
### Exceptional Cases
|
|
287
|
+
|
|
288
|
+
The following are also exceptional pathname cases:
|
|
289
|
+
|
|
290
|
+
- Here
|
|
291
|
+
- It
|
|
292
|
+
- Errors
|
|
293
|
+
- Gloo System Objects
|
|
294
|
+
|
|
295
|
+
Here is an example of objects and a pathname reference to an object within the hierarchy:
|
|
296
|
+
|
|
297
|
+
```gloo
|
|
298
|
+
#
|
|
299
|
+
# Hierarchical containers.
|
|
300
|
+
#
|
|
301
|
+
a [can] :
|
|
302
|
+
b [can] :
|
|
303
|
+
c [string] : Hello World
|
|
304
|
+
on_load [script] : show a.b.c
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
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`.)
|
data/docs/operators.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Operators
|
|
2
|
+
|
|
3
|
+
Gloo operators can be used to do basic math and to compare values.
|
|
4
|
+
|
|
5
|
+
**Contents**
|
|
6
|
+
|
|
7
|
+
- Math Operators
|
|
8
|
+
- Comparison Operators
|
|
9
|
+
- Example
|
|
10
|
+
|
|
11
|
+
## Math Operators
|
|
12
|
+
|
|
13
|
+
These are the gloo math operators:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
+ addition
|
|
17
|
+
- subtraction
|
|
18
|
+
* multiplication
|
|
19
|
+
/ division
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Comparison Operators
|
|
23
|
+
|
|
24
|
+
Strings, integers, and decimal numbers can be compared.
|
|
25
|
+
|
|
26
|
+
These are the gloo comparison operators:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
= equal (== also works, as an alternate spelling — not a separate identity check)
|
|
30
|
+
!= not equal
|
|
31
|
+
> greater than
|
|
32
|
+
< less than
|
|
33
|
+
>= greater than or equal to
|
|
34
|
+
<= less than or equal to
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Example
|
|
38
|
+
|
|
39
|
+
Here are some examples of math operator usage:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
> show 2 + 5
|
|
43
|
+
> put 12 / 3 into x
|
|
44
|
+
> show 23 * 3 - 6
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
And some examples of comparison operator usage:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
> show 2 = 2
|
|
51
|
+
> show 2 != 2
|
|
52
|
+
> show 2 > 2
|
|
53
|
+
> show 2 < 2
|
|
54
|
+
> show 2 >= 2
|
|
55
|
+
> show 2 <= 2
|
|
56
|
+
|
|
57
|
+
> if a = b then show "the strings are equal"
|
|
58
|
+
> if x > y then run my_script
|
|
59
|
+
> put x != y into my_bool
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
See also: Put, Show.
|