Adds hostname, stdin, stdout, and stderr. Updates readme.

master
sloum 2 years ago
parent 019c076dba
commit b5a8f79d22

@ -104,9 +104,12 @@ There are a number of special forms in the language that will allow, for example
#### Values
`PI`, `E`, `sys-args`
`PI`, `E`, `sys-args`, `stdin`, `stdout`, `stderr`
_Note_: `sys-args` is populated with the arguments run at the command line, similar to C's `argv`
`sys-args` is populated with the arguments run at the command line, similar to C's `argv`
`stdin`, `stdout`, and `stderr` are set at runtime to an open IOHandle representing each IO file. This makes it easy to read or write to any of them the same as you would any other file (by passing the IOHandle to the reader/writer).
#### Number related
@ -260,7 +263,7 @@ Implemented:
Implemented:
`newline`, `display`, `display-lines`, `write`, `write-raw`, `read-line`, `read-char`, `read-all`, `read-all-lines`, `close` `file-create`, `file-open-read`, `file-open-write`, `file-append-to`, `file-stat`
`newline`, `display`, `display-lines`, `write`, `write-raw`, `read-line`, `read-char`, `read-all`, `read-all-lines`, `close` `file-create`, `file-create-temp`, `file-open-read`, `file-open-write`, `file-append-to`, `file-stat`, `file-name`
Not implemented, but on my radar:
@ -368,7 +371,7 @@ Implemented:
Implemented:
`net-conn`, `url-scheme`, `url-host`, `url-port`, `url-path`, `url-query`
`net-conn`, `url-scheme`, `url-host`, `url-port`, `url-path`, `url-query`, `hostname`
_Note_: For the time being, `net-conn` can be used to make most requests. At the moment the tls settings are not particularly secure and I am looking into ways to allow for more granular customization of both the timeout and the tls without weighing down the function or introducing more types.
@ -384,6 +387,7 @@ _Note_: For the time being, `net-conn` can be used to make most requests. At the
<li><code>(url-port [url: string] [[new-port: string]])</code>: <code>string</code></li>
<li><code>(url-path [url: string] [[new-path: string]])</code>: <code>string</code></li>
<li><code>(url-query [url: string] [[new-query: string]])</code>: <code>string</code></li>
<li><code>(hostname)</code>: <code>string</code></li>
</ul>
</details>

@ -25,6 +25,9 @@ import (
// TODO add proc to manually force/throw a panic
var stdLibrary = vars{
"stdin": &IOHandle{os.Stdin, true},
"stdout": &IOHandle{os.Stdout, true},
"stderr": &IOHandle{os.Stderr, true},
"PI": number(math.Pi),
"E": number(math.E),
"sys-args": func(a ...expression) expression {
@ -1675,6 +1678,13 @@ var stdLibrary = vars{
}
return StringSliceToExpressionSlice(g)
},
"hostname": func(a ...expression) expression {
hostname, err := os.Hostname()
if err != nil {
return exception("'hostname' could not retrieve the hostname: " + err.Error())
}
return hostname
},
"net-conn": func(a ...expression) expression {
// (net-conn host port use-tls timeout-seconds)
// (net-conn string string bool number)

Loading…
Cancel
Save