Skip to content
This repository has been archived by the owner on Jul 3, 2020. It is now read-only.

Internal API

facekapow edited this page Mar 24, 2016 · 5 revisions

Note: the following was added by @facekapow (NOT the author of runtime.js) and is only partially documented.


require('runtimejs')

These are things accessible through requiring 'runtimejs':


runtime.tty

Terminal interface object

runtime.tty.color {}

Collection of colors for the terminal interface.

runtime.tty.print(text, [repeat], [fg], [bg])

Prints text to the terminal. Reprinted repeat time(s). fg for text color, bg for background text color.

runtime.tty.moveOffset(offset)

Moves screen position by adding the offset.

runtime.tty.moveTo(x, y)

Moves screen to specified x and y coordinates. Unlike moveOffset(), it is not relevant to the current screen position.


runtime.stdio

Provides a stdio interface with the user. Mainly used outside of shell commands.

runtime.stdio.StdioInterface class

This is used mainly with runtime.shell.runCommand(). Stdio interface class.

new StdioInterface():

Accessible through a new runtime.stdio.StdioInterface

Resettable

These functions can be overridden, probably for capturing IO.

interface.onwrite(text)

On write of text without appending a newline, this function is called with the text.

interface.onwriteline(text)

On write of text with appending a newline, this function is called with the text.

interface.onwriteerror(err)

On write of an error, this function is called with the error as a string.

interface.onread(cb)

On read of a single char, this function is called with a callback that accepts a string (but only reads the first character).

interface.onreadline(cb)

On read of a line, this function is called with a callback that accepts a string.

Useable

These functions are only to be used, and cannot be overridden.

interface.write(...text)

Calls interface.onwrite() with the text joined as a string.

interface.writeLine(...text)

Calls interface.onwriteline() with the text joined as a string and a newline appended.

interface.writeError(error)

Calls interface.onwriteerror() with error as a string. If given a string, it passes it without modifying it. If given an error object, it reads the error's stack property.

interface.read(cb)

Calls interface.onread() with cb. cb should accept a string parameter.

interface.readLine(cb)

Calls interface.onreadline() with cb. cb should accept a string parameter (does not include the newline).

runtime.stdio.defaultStdio StdioInterface

The default stdio interface for runtime, again, mainly used outside of shell commands. It's an instance of runtime.stdio.StdioInterface that inputs and outputs (including errors) to the shell.


runtime.keyboard

Keyboard functions provided

runtime.keyboard.onKeydown EventController

Event controller for key down events. By default has one listener (the terminal input controller).

runtime.keyboard.onKeyup EventController

Event controller for key up events.


runtime.pci

PCI controller for runtime.js, also enables device drivers.

runtime.pci.addDriver(vendorId, deviceId, opts)

Finds device using vendorId and deviceId and, if found, sets opts as device driver.


runtime.ps2

PS2 controller for runtime.js

runtime.ps2.setKeyboardDriver(driver)

Sets driver as driver for keyboard.


runtime.allocator

runtime.js memory allocator interface.

runtime.allocator.allocDMA()

Returns some allocated memory.


runtime.net

Network access in runtime.js

runtime.net.interfaceAdd(intf)

Adds intf to the interfaces available to runtime.js Useful for network adapters.

runtime.net.TCPSocket class

runtime.js TCPSocket interface class, provides access to a TCPSocket. See the runtime.net.TCPSocket page. (yet to be created)

runtime.net.TCPServerSocket class

runtime.js TCPServerSocket interface class, provides access to a TCPSocket server. See the runtime.net.TCPSocket page. (yet to be created)

runtime.net.UDPSocket class

runtime.js UDPSocket interface class, provides access to a UDPSocket. See the runtime.net.UDPSocket page. (yet to be created)

runtime.net.IP4Address(a, b, c, d)

Creates an IP4Address object from a, b, c, and d, without the dots.

runtime.net.MACAddress(a, b, c, d, e, f)

Creates a MACAddress object from a, b, c, d, e, and f, without the colons.

runtime.net.Interface(macAddr)

Creates an Interface object from the given macAddr, which must be an instance of runtime.net.MACAddress.

runtime.net.route {}

Collection of IP route functions

runtime.net.route.addSubnet(ip, mask, gateway, intf)

Adds a new subnet route

runtime.net.route.addDefault(gateway, intf)

Adds the specifed gateway and intf as the default.

runtime.net.route.lookup(destIP, intf)

Lookup the destIp route using interface intf.

runtime.net.onInterfaceAdded EventController

Controller triggered when an interface is added.

runtime.net.onInterfaceRemoved EventController

Controller triggered when an interface is removed.


runtime.bufferAdress(u8)

Gets the memory address of the u8 buffer.


runtime.debug bool

In debug mode? true or false, default false.


runtime.machine

Native functions

runtime.machine.shutdown()

Shuts down the computer.

runtime.machine.reboot()

Reboots the computer.


runtime.shell

Shell access for isolates.

runtime.shell.setCommand(name, cb)

Creates a new shell command accessible to the user via typing the name in the shell and calls cb when activated.

cb should be something like:

runtime.shell.setCommand('foo', function(args, env, done) {
  // `args` is a string,
  // `env` is the command's environment object,
  // and done is called like done([return code]) which tells the shell you're done.
});

runtime.shell.runCommand(name, [opts], [cb])

Runs shell command name. opts should be an object, and accepts:

  • args - A string containing arguments for the command,
  • stdio - A runtime.stdio.StdioInterface to pipe stdio to.

ex:

var myio = new runtime.stdio.StdioInterface();
myio.onwriteline = function(text) {
  console.log('hey! we got: ' + text);
};
myio.onreadline = function(cb) {
  cb('foo');
};

runtime.shell.runCommand('foobar', {
  args: 'someargs',
  stdio: myio
}, function(retcode) {
  console.log('exit with ' + retcode);
});

runtime.dns

DNS interface for isolates.

runtime.dns.resolve(domain, opts, cb)

Resolve domain with options opts, and when done call cb with the result. Example code:

runtime.dns.resolve('www.google.com', {}, function(result) {
  console.log(JSON.stringify(result));
});

Example output:

{"hostname":"www.google.com","results":[{"hostname":"www.google.com","record":"A","address":[216,58,219,164],"ttl":144}]}
Clone this wiki locally