< Home | Recrafted | Blog | About >

Recrafted 1.3.0 / Threading

One of the bigger differences in Recrafted over CraftOS is its native support for cooperative multithreading.  The provided threading implementation is heavily integrated into the Multishell implementation.

The API is referred to here as thread, but its name in Recrafted is rc.thread.

  thread.launchTab(x[, name]): numbernumber
    Spawns a new thread and launches it in a new tab.  Returns the new tab ID and the thread ID.  x may be a string or a function.

  thread.setFocusedTab(f)
    Sets which tab is the focused tab.  Tab IDs are sequential and subject to fluctutation.

  thread.getFocusedTab(): number
    Returns the ID of the currently focused tab.

  thread.getCurrentTab(): number
    Returns the ID of the tab the current thread is running in.

  thread.load(file[, name]): number
    Loads a file and spawns a thread using the resulting function.  The name defaults to the file path.  Returns the ID of the new thread.

  thread.spawn(funcname): number
    Spawns a thread using the given function.  Returns its ID.

  thread.exists(id): boolean
    Returns whether the thread with the given ID exists.

  thread.id()
    Returns the ID of the current thread.

  thread.dir(): string
    Returns the current working directory.

  thread.setDir(dir)
    Sets the current working directory, if the given dir exists and is a directory.

  thread.vars(): table
    Returns the environment variables of the current thread.

  thread.getTerm(): 
    Returns the current terminal redirect object.

  thread.setTerm(new)
    Sets the current tab's terminal redirect object.

  thread.info(): table
    Returns a table of information about every running thread.

  thread.remove([id])
    Removes the given thread.  Use with caution.