Shared Module playxlib

Function Summary

static CastToBool(v, default)
Casts a console command arg to a bool.
static CastToNumber(v, default)
Casts a console command arg to a number.
static CastToString(v, default)
Casts a console command arg to a string.
static EmptyToNil(s)
Returns nil if a string is empty, otherwise it will return the string.
static FindMatch(str, patterns)
Attempts to match a list of patterns against a string, and returns the first match, or nil if there were no matches.
static HTMLEscape(str)
HTML encodes a string.
static HTMLUnescape(s)
Unescape HTML.
static IsSquare(width, height)
Takes a width and height and returns a boolean to indicate whether the shape is optimally a square.
static IsTrue(s)
Tries to interpret a string as a boolean.
static JSEscape(str)
Encodes a string to be placed into a JavaScript string.
static ParseCSV(data)
Parses a string containing data formatted in CSV into a table.
static ParseQuery(str)
Parses a query.
static ParseTags(s, delim)
Gets the tags out of a string.
static ParseTimeString(str)
Parses a human-readable time string.
static PointLineDistance(line1, line2, point)
Returns the smallest distance between a point and a line in 3D space.
static PointLineSegmentDistance(line1, line2, point)
Returns the smallest distance between a point and a line segment in 3D space.
static PointLineSegmentProjection(line1, line2, point)
Returns the projection of a point onto a line segment in 3D space.
static ReadableTime(t)
Turns seconds into minutes and seconds.
static URLEscape(s)
Percent encodes a value for URLs.
static URLEscapeTable(vars)
Percent encodes a table for the query part of a URL.
static URLUnescape(str)
URL unescapes a string.
static UTCTime(t)
Gets a timestamp in UTC.
static WriteCSV(data)
Turns a table into CSV data.

Functions

CastToBool

playxlib.CastToBool(v, default)

Casts a console command arg to a bool.

Parameters:

  • v
  • default

Return value:

  • Boolean

CastToNumber

playxlib.CastToNumber(v, default)

Casts a console command arg to a number.

Parameters:

  • v
  • default

Return value:

  • Boolean

CastToString

playxlib.CastToString(v, default)

Casts a console command arg to a string.

Parameters:

  • v
  • default

Return value:

  • Boolean

EmptyToNil

playxlib.EmptyToNil(s)

Returns nil if a string is empty, otherwise it will return the string.

Parameters:

  • s - String

Return value:

  • Value

FindMatch

playxlib.FindMatch(str, patterns)

Attempts to match a list of patterns against a string, and returns the first match, or nil if there were no matches.

Parameters:

  • str - The string
  • patterns - Table of patterns

Return value:

  • Table of results, or bil

HTMLEscape

playxlib.HTMLEscape(str)

HTML encodes a string.

Parameters:

  • str

Return value:

  • Encoded string

HTMLUnescape

playxlib.HTMLUnescape(s)

Unescape HTML. This function fudges the job, and it does not handle all of HTML's named entities.

Parameters:

  • s - The string

Return value:

  • Unescaped string

IsSquare

playxlib.IsSquare(width, height)

Takes a width and height and returns a boolean to indicate whether the shape is optimally a square. This is used by the engine code to determine whether a square screen is better than a rectangular screen for a certain set of screen dimensions.

Parameters:

  • width
  • height

Return value:

  • Boolean

IsTrue

playxlib.IsTrue(s)

Tries to interpret a string as a boolean. "true," "y," etc. are considered to be true.

Parameters:

  • s - String

Return value:

  • Boolean

JSEscape

playxlib.JSEscape(str)

Encodes a string to be placed into a JavaScript string.

Parameters:

  • str - String to encode

Return value:

  • Encoded

ParseCSV

playxlib.ParseCSV(data)

Parses a string containing data formatted in CSV into a table. Fields can be quoted with double quotations or be unquoted, and characters can be escaped with a backslash. This CSV parser is very forgiving. The return table has each line in a new entry, and each field is then a further entry in a table. Not all the rows may have the same number of fields in the returned table.

Parameters:

  • data - CSV data

Return value:

  • Table containg data

ParseQuery

playxlib.ParseQuery(str)

Parses a query.

Parameters:

  • str - String to parse

Return value:

  • Table with keys and values

ParseTags

playxlib.ParseTags(s, delim)

Gets the tags out of a string.

Parameters:

  • s
  • delim - Delimiter

Return value:

  • Table

ParseTimeString

playxlib.ParseTimeString(str)

Parses a human-readable time string. Returns the number in seconds, or nil if it cannot detect a format. Blank strings will return 0.

Parameters:

  • str

Return value:

  • Time

PointLineDistance

playxlib.PointLineDistance(line1, line2, point)

Returns the smallest distance between a point and a line in 3D space.

Parameters:

  • line1 - Line's first point
  • line2 - Line's second point
  • point - Point

Return value:

  • Distance

PointLineSegmentDistance

playxlib.PointLineSegmentDistance(line1, line2, point)

Returns the smallest distance between a point and a line segment in 3D space.

Parameters:

  • line1 - Line's first point
  • line2 - Line's second point
  • point - Point

Return value:

  • Distance

PointLineSegmentProjection

playxlib.PointLineSegmentProjection(line1, line2, point)

Returns the projection of a point onto a line segment in 3D space.

Parameters:

  • line1 - Line's first point
  • line2 - Line's second point
  • point - Point

Return value:

  • Distance

ReadableTime

playxlib.ReadableTime(t)

Turns seconds into minutes and seconds.

Parameters:

  • t - Time

Return value:

  • String

URLEscape

playxlib.URLEscape(s)

Percent encodes a value for URLs.

Parameters:

  • s - String

Return value:

  • Encoded

URLEscapeTable

playxlib.URLEscapeTable(vars)

Percent encodes a table for the query part of a URL.

Parameters:

  • vars - Table of keys and values

Return value:

  • Encoded string

URLUnescape

playxlib.URLUnescape(str)

URL unescapes a string. Doesn't handle %####

Parameters:

  • str - String

Return value:

  • Unescaped string

UTCTime

playxlib.UTCTime(t)

Gets a timestamp in UTC.

Parameters:

  • t - Time

Return value:

  • Time

WriteCSV

playxlib.WriteCSV(data)

Turns a table into CSV data.

Parameters:

  • data - Table to convert

Return value:

  • CSV data