2017-07-30 19:12:10 +10:00
# API
## Functions
### system
#### spawn(*name*, *function*, *environment*)
Spawns a process from *function* called *name* with *environment* .
2017-09-06 18:35:18 +10:00
#### log(*messages...*, *severity*, *facility*, *meta*)
Writes messages to the system log, optionally, if *meta* is true, with *severity* and *facility* , which default to 6 and 2, respectively.
2017-07-31 12:25:20 +10:00
2017-07-30 19:12:10 +10:00
### os
#### os.getenv(*k*)
Gets the *k* environment variable for the current process.
#### os.setenv(*k*, *v*)
Sets the *k* environment variable to *v* for the current process.
#### os.tasks()
Returns a list of current processes running, the key being the pid and the value being the name.
#### os.taskinfo(*pid*)
Returns the name, parent process, and user ID for process *pid* .
2017-09-06 18:35:18 +10:00
#### os.genenv()
Generates an insulated environment table for running processes in.
2017-07-31 12:25:20 +10:00
2017-07-30 19:12:10 +10:00
### event
#### event.get()
Gets the next event in the event queue for the process.
2017-08-03 17:55:17 +10:00
#### event.pull(*type*,*timeout*)
Gets, and possibly waits for up to *timeout* seconds, for an event, optionally with *type* .
2017-07-31 12:25:20 +10:00
2017-07-30 19:12:10 +10:00
### buffer
#### buffer.create(*w*, *c*)
2017-09-06 18:35:18 +10:00
**DEPRECEATED.** Creates a buffer with worker function *w* and close function *c* . *w* is called on creation with the buffer as the argument.
#### buffer.ucreate()
Creates a unidirectional buffer and returns it.
#### buffer.bcreate()
Creates a bidiretional buffer and returns both ends.
2017-07-31 12:25:20 +10:00
### filesystem
#### fs.mount(*mp*, *pr*)
Mounts the component proxy *pr* to mountpoint *mp* .
#### fs.simplify(*path*)
Simplifies *path* by resolving .. and . and similar.
#### fs.resolve(*path*)
Resolves *path* to a table of path elements, a mountpoint and a relative filesystem path.
#### fs.open(*path*,*mode*)
Returns a system file handle usable by other fs functions for *path* in *mode* . Modes can be r, w, a, rb, wb, ab.
#### fs.close(*handle*)
Closes a system file handle.
#### fs.read(*handle*,*length*)
Reads *length* bytes of data from *handle* . *length* is usually limited to 2048.
#### fs.write(*handle*,*data*)
Writes *data* to *handle* .
#### fs.readall(*handle*)
Returns as much data as can be read from *handle* .
2017-08-01 21:41:54 +10:00
#### fs.list(*path*)
Returns a table of files contained in directory *path*
#### fs.mkdir(*path*)
Creates a directory at *path*
#### fs.rm(*path*)
Removes a file or (empty) directory at *path* .
#### fs.exists(*path*)
Returns true if a file or directory *path* exists.
#### fs.isdir(*path*)
Returns true if *path* is a directory.
#### fs.cd(*path*)
Changes the current directory to either *path* or *os.getenv("PWD")* /*path*.
2017-09-06 18:35:18 +10:00
#### fs.cp(*source*, *destination*)
Copies a file from *source* to *destination* .
#### fs.mv(*source*, *destination*)
Same as fs.cp but deletes *source* afterwards.
2017-07-31 12:25:20 +10:00
### io
#### write(...) or io.write(...)
2017-07-30 19:12:10 +10:00
Writes its arguments to the I/O device.
#### print(...)
Writes its arguments to the I/O device, with a newline after each.
2017-07-31 12:25:20 +10:00
#### readln(*rch*) or io.read(...)
Reads a line from the I/O device, optionally replacing the echoed characters with *rch* .a
#### io.open(*path*,*mode*)
Returns a file object for *path* in *mode* .
##### fobj:read(*len*)
If *len* is a number, reads *len* bytes from *fobj* . If *len* is "\*a", it reads all the data from *fobj* . If *len* is "\*l", it reads a line from *fobj* .
##### fobj:write(*data*)
Writes *data* to *fobj* (if in write mode)
##### fobj:close()
Closes *fobj* , flushing buffers and removing the object from memory.
2017-08-01 21:41:54 +10:00
### shutil
#### cd(*path*)
Alias to fs.cd
#### rm(*path*)
Alias to fs.rm
#### mkdir(*path*)
Alias to fs.mkdir
#### ls(*path*)
Wrapper for fs.list that prints the contents of *path* .
#### cat(*path*)
Prints the contents of the file *path* .
2017-08-03 17:55:17 +10:00
#### ps(*filter*)
Prints running processes, optionally matching *filter* .
#### mem()
Print out some memory info.
### net
#### net.send(*addr*,*port*,*msg*)
Sends *msg* to *addr* on *port* .
#### net.sendstring(*addr*,*port*,*msg*)
Sends *msg* to *addr* on *port* in *net.mtu* sized chunks.
#### net.recvstring(*addr*,*port*)
2017-08-01 21:41:54 +10:00
2017-09-06 18:35:18 +10:00
### cdlib
cdlib is the Copper Data Library
#### cdlib.encode(*hops*, *source*, *destination*, *data*)
Encodes a copper packet with *hops* from *source* to *destination* with *data* .
#### cdlib.decode(*data*)
Decodes a copper packet. Returns the same data cdlib.encode takes as input.
#### cdlib.encodeName(*name*)
Encodes a name for use in a copper packet.
#### cdlib.decodeName(*message*)
Returns just the name from an encoded copper packet.
#### cdlib.decodeNoHops(*data*)
Decodes a copper packet minus the hops.
### relib
relib is the Copper reliability layer library.
#### relib.encode(*packet*)
Encodes *packet* passed as a table as a relib packet.
#### relib.decode(*data*)
Decodes *data* into a relib packet table.
2017-07-30 19:12:10 +10:00
### drivers
#### tty(*gA*, *sA*, *sI*, *fg*, *bg*)
Creates a GPU driver instance for GPU *gA* and screen *sA* attached to session *sI* , optionally with foreground and background colours *fg* and *bg* .
#### kbd(*kA*, *sI*)
Creates a keyboard driver instance for keyboard *kA* attached to session *sI* .
2017-07-31 12:25:20 +10:00
2017-07-30 19:12:10 +10:00
## Events
### Network
#### net\_msg, *from*, *port*, *message*
Queued when the system receives message *message* from *from* on port *port* .
2017-07-31 12:25:20 +10:00
2017-07-30 19:12:10 +10:00
### Terminal I/O
#### key, *session*, *char*, *code*
A key with value *char* and code *code* was pressed and parsed by a keyboard handler attached to session *session*
#### display, *session*, *text*
This is triggered to make a tty driver attached to *session* write *text* to the screen. Ideally, use write(), not the raw event.
2017-07-31 12:25:20 +10:00
2017-07-30 19:12:10 +10:00
## Applications
### luash(*sI*)
Spawns a luash instance for session *sI*
2017-09-06 18:35:18 +10:00
### skex(*fname*)
Launches an instance of the skex text editor, optionally reading *fname* at startup.
May actually spawn skex2.
### skex2(*fname*)
2017-08-03 17:55:17 +10:00
Launches an instance of the skex2 text editor, optionally reading *fname* at startup.
2017-09-06 18:35:18 +10:00
### nsh(*host*, *port*)
Spawns the network shell client and attempts to connect to *host* on *port* for a remote login session.
ctrl-shift-c to exit.
### nshd(*port*)
Spawns a networh shell server listening on *port.*