< Home | Recrafted | Blog | About >

Recrafted 1.4.0 / cc.strings API extensions

Recrafted features a few extra functions in its implementation of the cc.strings API.

  strings.splitElements(text[, limit]): table
    Splits text into a set of tokens.  The returned table is an array containing many instances of the following structure:

      {
        text = string,
        type = string
      }


    The type field will be "ws" for whitespace, "nl" for one or more newlines, and "word" for any other text.

    The returned table is valid as the first argument of strings.wrappedWriteElements.

  strings.wrappedWriteElements(elements, widthdoHalves, handler)
    Write all the elements given in elements to the screen.

    elements is a table in the same format returned by strings.splitElements.
    width is the width to wrap to.
    If doHalves is true, then words longer than half the given width will be wrapped given certain conditions.

    The handlers table must contain three functions:

      newline(): Write a newline.
      append(text): Append some text to the current line.
      getX(): number: Return the current position on the current line.

    strings.wrap, rc.write, and textutils.coloredWrite all make use of this function.  They may be referred to for sample usage.