Environment variables: Difference between revisions

No edit summary
 
(One intermediate revision by one other user not shown)
Line 582:
writeln "USER: ", _env["USER"]</syntaxhighlight>
 
{{works with|langur|0.9}}
We could also the short-hand form of indexing by string. This is limited to code points used for tokens and does not allow for spaces, nor an index alternate.
<syntaxhighlight lang="langur">writeln "HOME: ", _env'HOME
Line 1,338 ⟶ 1,337:
 
However, if Wren is embedded in (say) a suitable Go program, then we can ask the latter to obtain it for us.
<syntaxhighlight lang="ecmascriptwren">/* environment_variablesEnvironment_variables.wren */
class Environ {
foreign static variable(name)
Line 1,347 ⟶ 1,346:
which we embed in the following Go program and run it.
{{libheader|WrenGo}}
<syntaxhighlight lang="go">/* environment_variablesEnvironment_variables.go */
package main
 
Line 1,364 ⟶ 1,363:
func main() {
vm := wren.NewVM()
fileName := "environment_variablesEnvironment_variables.wren"
methodMap := wren.MethodMap{"static variable(_)": getEnvironVariable}
classMap := wren.ClassMap{"Environ": wren.NewClass(nil, nil, methodMap)}
885

edits