This file documents the LoLa Standard Library, a set of basic routines to enable LoLa programs.
Length(string): numberReturns the length of the string.
SubString(string, start, [length]): stringReturns a portion of string. The portion starts at start and is length bytes long. If length is not given, only the start of the string is cut.
Trim(string): stringRemoves leading and trailing white space from the string. White space is on of the following ascii characters:
0x09 (horizontal tab)0x0A (line feed)0x0B (vertical tab)0x0C (form feed)0x0D (carriage return)0x20 (space)TrimLeft(string): stringRemoves leading white space from the string.
TrimRight(string): stringRemoves trailing white space from the string.
IndexOf(string, text): number|voidSearches for the first occurrence text in string, returns the offset to the start in bytes. If text is not found, void is returned.
LastIndexOf(string, text): number|voidSearches for the last occurrence of text in string, returns the offset to the start in bytes. If text is not found, void is returned.
Byte(string): numberReturns the first byte of the string as a number value. If the string is empty, void is returned, if the string contains more than one byte, still only the first byte is considered.
Chr(byte): stringReturns a string of the length 1 containing byte as a byte value.
NumToString(num, [base]=10): stringConverts the number num into a string represenation to base base. If base is given, it will format the integer value of the number to base, otherwise, a decimal floating point output will be given.
StringToNum(str, [base]=10): number|voidConverts the string str to a number. If base is not given, the number is assumed to be base 10 and a floating point value. Otherwise, base is used as the numeric base for conversion, and only integer values are accepted.
If the conversion fails, void is returned.
If base is 16, 0x is accepted as a prefix, and h as a postfix.
Split(str, sep, [removeEmpty]): arraySplits the string str into chunks separated by sep. When removeEmpty is given and true, all empty entries will be removed.
Join(array, [sep]): stringJoins all items in array, optionally separated by sep. Each item in array must be a string.
Array(count, [init]): arrayReturns an array with count items initialized with init if given. Otherwise, the array will be filled with void.
Range(count): arrayReturns an array with count increasing numbers starting at 0.
Range(start, count)Returns an array with count increasing numbers starting at start.
Length(array): numberReturns the number of items in array.
Slice(array, start, length): arrayReturns a portion of the array, starting at index (inclusive) and taking up to length items from the array. If less items are possible, an empty array is returned.
IndexOf(array, item): number|voidReturns the index of a given item in array. If the item is not found, void is returned.
LastIndexOf(array, item): number|voidReturns the last index of a given item in array. If the item is not found, void is returned.
Pi: numberGlobal constant containing the number pi.
DeltaEqual(a, b, delta): booleanCompares a and b with a certain delta. Returns true when abs(a-b) < delta.
Rounds x towards negative infinity.
Rounds x towards positive infinity.
Rounds x to the closest integer.
Sin(a): number, Cos(a): number, Tan(a): numberTrigonometric functions, all use radians.
Atan(y, [x]): numberCalculates the arcus tangens of y, and, if x is given, divides y by x before.
Use the two-parameter version for higher precision.
Sqrt(x): numberCalculates the square root of x.
Pow(v, e): numberReturns v to the power of e.
Log(v, [base]): numberReturns the logarithm of v to base base. If base is not given, base 10 is used.
Exp(v): numberReturns e to the power of v. e is the euler number.
Random([min],[max]): numberReturns a random number between min and max. If no argument is given, a random number between 0.0 and 1.0 is returned. If only min is given, a number between 0.0 and min (inclusive) is returned.
RandomInt([min],[max]): numberReturns a random integer between min and max. If no argument is given, a random positive number is returned. If only min is given, a number between 0 and min (exclusive) is returned.
Sleep(secs): voidSleeps for secs seconds.
Timestamp(): numberReturns the current wall clock time as a unix timestamp.
TypeOf(arg): stringReturns the type of the argument as a string. Returns one of the following:
"void", "boolean", "string", "number", "object", "array"
ToString(val): stringConverts the input val into a string representation.
HasFunction(name): booleanReturns true if the current environment has a function called name, false otherwise.
HasFunction(object, name): booleanReturns true if the object has a function called name, false otherwise.
Serialize(value): stringSerializes any value into a binary representation. This representation can later be loaded by via Deserialize and return the exact same value again. Note that objects are stored as opaque handles and are not transferrable between different systems.
Deserialize(string): anyDeserializes a previously serialized value. If the deserialization fails, a panic will occurr.
Yield(): voidThis function will yield control back to the host, pausing the current execution. This can be inserted in loops to reduce CPU usage.