OC-PsychOS/docs/api.md

47 lines
1.9 KiB
Markdown
Raw Normal View History

2017-07-30 19:12:10 +10:00
# API
## Functions
### system
#### spawn(*name*, *function*, *environment*)
Spawns a process from *function* called *name* with *environment*.
### 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*.
### event
#### event.get()
Gets the next event in the event queue for the process.
#### event.pull(*type*)
Gets, and possibly waits, for an event, optionally with *type
### buffer
#### buffer.create(*w*, *c*)
Creates a buffer with worker function *w* and close function *c*. *w* is called on creation with the buffer as the argument.
### I/O stuff
#### write(...)
Writes its arguments to the I/O device.
#### print(...)
Writes its arguments to the I/O device, with a newline after each.
#### readln(*rch*)
Reads a line from the I/O device, optionally replacing the echoed characters with *rch*.
### 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*.
## Events
### Network
#### net\_msg, *from*, *port*, *message*
Queued when the system receives message *message* from *from* on port *port*.
### 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.
## Applications
### luash(*sI*)
Spawns a luash instance for session *sI*