WildStar:UI Lua

Revision as of 03:09, 9 August 2023 by Bear (talk | contribs) (Bear moved page WildStar/UI Lua to //UI Lua)

Template:UI Lua/uilua This is the main reference for the WildStar Lua runtime, as implemented in the WildStar UI. See also [[../UI API/]].

The WildStar Lua runtime is based on Lua 5.1, and generally uses the same standard Lua functions listed on the official Lua web site. Some functions differ slightly in WildStar's implementation and are documented here as well for consistency.

Reference

Nearly all of these functions are part of the default Lua 5.1 runtime environment, described here. Notable omissions are the operating system, and file I/O libraries.

/eval Print(_VERSION)
[debug]: Lua 5.1

Basic

Template:UI Lua/id(val[, sMsg]) returns (val) - returns val if true, else throws Lua error with sMsg
Template:UI Lua/id() - forces garbage collection
Template:UI Lua/id([filename]) - opens the named file and executes its contents as a Lua chunk (stdio not usable in UI)
Template:UI Lua/id(sMsg, level) - throws error with message. use pcall() to catch errors
Template:UI Lua/id() returns (nAddOn,nLimit) - gets AddOn memory used and current GC threshold in kB
Template:UI Lua/id(any) returns (table) - gets stack frame of given function or stack level number
Template:UI Lua/id(aObject) returns (mtable) - gets metatable for table or userdata
Template:UI Lua/id(func [, chunkname]) returns (function) - gets Lua chunk from func stream, until empty, nil, no value
Template:UI Lua/id([filename]) returns (function) - similar to load, but gets from file (stdio not usable in UI)
Template:UI Lua/id(string [, chunkname]) returns (function) - gets Lua chunk for a Lua code string
Template:UI Lua/id(boolean or proxy) - creates a userdata with a sharable metatable
Template:UI Lua/id(table, index) returns (key,value) - gets next key-value pair of the table, allowing you to walk a table
Template:UI Lua/id(func, arg1, arg2, ...) returns (boolean, results or sMessage) - executes 'func' and returns true and values, otherwise false and error message
Template:UI Lua/id(string) - prints to Lua stdio (stdio not usable from UI)
Template:UI Lua/id(v1, v2) returns (boolean) - checks if v1 and v2 are equal, bypassing any metamethods
Template:UI Lua/id(table, index) - gets real value of table[index], bypassing any metamethods
Template:UI Lua/id(table, index, value) - sets real table[index] to value, bypassing any metamethods
Template:UI Lua/id(nIndex, list) returns (number or item) - gets count if 'index' is "#", or item at 'index'
Template:UI Lua/id(function or integer, table) - sets table representing the stack frame for given function or stack level
Template:UI Lua/id(aObject, mtable) returns (any) - sets the metatable of a table or userdata, returns aObject
Template:UI Lua/id(any) - gets type of variable as a string: "number", "string", "table", "function" or "userdata"
Template:UI Lua/id(table[, nStart][, nEnd]) returns (...) - converts indexed values of table to an argument list
Template:UI Lua/id(function, fCallback) returns (boolean,results) - true if successfully executes function, or executes fCallback and returns false. results are return values of function or fCallback

WS UI offers these standard Lua global data vars

Template:UI Lua/id [table] - canonical list of variables in global scope, including ones in this reference
Template:UI Lua/id [string] = "Lua 5.1" - printable Lua runtime version number

Strings

These string functions are Carbine custom, shorthand references to or a part of the Lua string library "string." See StringLibraryTutorial for more info.

Template:UI Lua/id(any[, base]) returns (number) - converts any. nil if fails. non-10 bases accept only unsigned ints
Template:UI Lua/id(any) - converts to a string, or nil if fails.

These are custom string functions available in WS but not normal Lua.

Template:UI Lua/id(any[, nPlaces]) returns (number) - converts to number and rounds, default places 0. (Carbine)

Template:UI Lua/id

Template:UI Lua/id(string[, index]) - gets internal Lua char (byte size number) of the i-th element of string
Template:UI Lua/id(nByte[, ...]) - compiles one or more Lua chars (byte size numbers) into a string
Template:UI Lua/id(function) - returns a binary representation of the given function code as a string
Template:UI Lua/id(s, pattern[, start[, plain]]) - find match for pattern on s. optional offset or plain sub-string
Template:UI Lua/id(sFormat[, value[, ...]]) - gets string of values formatted by sFormat format string
Template:UI Lua/id(s, pattern) returns iterator function for pattern over the string s. (deprecated, same as gmatch)
Template:UI Lua/id(s, pattern) gets iterator that returns the next captures each call, using pattern on string s
Template:UI Lua/id(s, pattern, replacement[, nLimit]) - globally substitute pattern for replacement in string
Template:UI Lua/id(string) - return length of the string in Lua chars (byte size numbers)
Template:UI Lua/id(string) - return string converted to all lower case
Template:UI Lua/id(string, pattern[, initpos]) - similar to strfind, but only returns the matches, not the positions
Template:UI Lua/id(string, n [, sep]) - return a string which is n copies of s, with optional delimeter sep
Template:UI Lua/id(string) - reverses a string
Template:UI Lua/id(string, index[, endIndex]) - return a substring of string starting at index
Template:UI Lua/id(string) - return string converted to all upper case

Tables

These table functions are shorthand references to the Lua table library (which is available via "table.", see TableLibraryTutorial for more info). Be aware that some table functions only work with tables with proper numerical indexes, where {[1] = "x", [3] = "y"} would have only one indexed value at 1. Not being aware of this fact is one major causes for bugs in code written in Lua.

Template:UI Lua/id(table) - gets an iterator of type integer to traverse a table
Template:UI Lua/id(table) - gets an iterator to traverse a table

Template:UI Lua/id

Template:UI Lua/id(table [, sep [, i [, j]]]) returns (string) - build a string from table elements
Template:UI Lua/id(table, function) - runs function for each name-value in table. (deprecated, use pairs)
Template:UI Lua/id(table, function) - runs function for each index in table, in order. (deprecated, use ipairs)
Template:UI Lua/id(table) returns (number) - gets cached size of table array values. (deprecated, use #table operator)
Template:UI Lua/id(table[, pos], value) - insert value into table at pos. default is end of table
Template:UI Lua/id(table) returns (number) - last positive numerical index. requires scan of whole table
Template:UI Lua/id(table[, pos]) returns (any) - remove and return element at pos. default is last entry in table
Template:UI Lua/id(table, number) - attempts to set cached table size value. (deprecated, like getn)
Template:UI Lua/id(table[, comp]) - sort the elements in the table in-place, optionally using a custom comparator.

Arithmetic

Template:UI Lua/id

Template:UI Lua/id(value) - returns the absolute value of the number
Template:UI Lua/id(value) - returns the arc cosine of the value in degrees
Template:UI Lua/id(value) - returns the arc sine of the value in degrees
Template:UI Lua/id(value) - returns the arc tangent of the value in degrees
Template:UI Lua/id(y, x) - returns the arc tangent of Y/X in degrees
Template:UI Lua/id(value) - returns the ceiling of value
Template:UI Lua/id(degrees) - returns the cosine of the degree value
Template:UI Lua/id(value) - returns the hyperbolic cosine of value
Template:UI Lua/id(radians) - returns the degree equivalent of the radian value
Template:UI Lua/id(value) - returns the exponent of value
Template:UI Lua/id(value) - returns the floor of value
Template:UI Lua/id(x, y) - returns remainder of division of x by y, rounding quotient toward zero
Template:UI Lua/id(num) - Extract mantissa and exponent from a floating point number
Template:UI Lua/id = 1.#INF
Template:UI Lua/id(value, exponent) - Load exponent of a floating point number
Template:UI Lua/id(value) - returns the natural logarithm (log base e) of value
Template:UI Lua/id(value) - returns the base-10 logarithm of value
Template:UI Lua/id(value[, values...]) - returns the numeric maximum of the input values
Template:UI Lua/id(value[,values...]) - returns the numeric minimum of the input values
Template:UI Lua/id(a, b) - returns the integer remainder of a divided by b
Template:UI Lua/id(x) - returns two numbers. integral part of x, and fractional part of x
Template:UI Lua/id = 3.1415926535898
Template:UI Lua/id(x, y) - returns x to power of y. can also use operator ^, as expression x^y
Template:UI Lua/id(degrees) - returns the radian equivalent of the degree value
Template:UI Lua/id([ [lower,] upper]) - returns a random number, optionally bounded integer value
Template:UI Lua/id(x) - sets x "seed" for random generator. seed always makes same sequence
Template:UI Lua/id(degrees) - returns the sine of the degree value
Template:UI Lua/id(value) - returns the hyperbolic sine of value
Template:UI Lua/id(x) - returns the square root of x
Template:UI Lua/id(degrees) - returns the tangent of the degrees value
Template:UI Lua/id(x) - returns the hyperbolic tangent of x

Bitwise

WildStar includes the Lua BitLib library, which is available via "bit32." table, which provides access to C-style bitwise manipulation operators. This library uses the 32-bit integer size, e.g. bit32.lshift(2147483648, 1) = 0, because 1000 0000 0000 0000 0000 0000 0000 0000 -> 0000 0000 0000 0000 0000 0000 0000 0000.

Template:UI Lua/id

Template:UI Lua/id(a, b) - returns a shifted arithmetically right b places
Template:UI Lua/id(w1, ...) - returns the bitwise and of the w's
Template:UI Lua/id(a) - returns the one's complement of a
Template:UI Lua/id(w1, ...) - returns the bitwise or of the w's
Template:UI Lua/id(···) returns (boolean) - true if bitwise and of all operands is not zero
Template:UI Lua/id(w1, ...) - returns the bitwise exclusive or of the w's
Template:UI Lua/id(n, start[, width]) - gets set of bits from n. start is 0-31. default width is 1
Template:UI Lua/id(x, disp) - returns x rotated left disp places
Template:UI Lua/id(a, b) - returns a shifted left b places
Template:UI Lua/id(n, v, start [, width]) - gets copy n with bits set from value v. start is 0-31. default width is 1
Template:UI Lua/id(x, disp) - returns x rotated right disp places
Template:UI Lua/id(a, b) - returns a shifted logically right b places

System

The system functions whaich are generally just a subset of the Lua standard os library. Alternatively the {{../api||Apollo}} and {{../api|GameLib}} libraries offer standard WS UI date and time functions, like {{../api||GameLib|GetLocalTime}}, {{../api||GameLib|GetServerTime}} and {{../api||Apollo|GetTickCount}}.

Template:UI Lua/id

Template:UI Lua/id() - returns an approximation in seconds of CPU time used by the program
Template:UI Lua/id(t2, t1) - returns diff in seconds between t1 and t2. in Windows and others is exactly t2-t1
Template:UI Lua/id([table]) returns (number) - current machine time, or from date table, in secs since 00:00 Jan 1 1970
Template:UI Lua/id([format[, time]]) returns (table or string) - gets table or format string, of current or time date

Debugging

The debugging functions which are generally just a subset of the Lua stardard debug library.

Template:UI Lua/id

Template:UI Lua/id() enters an interactive mode with the user (not useable from UI)
Template:UI Lua/id([thread]) - gets thread's hook settings: function, mask, count
Template:UI Lua/id([thread,] f [, what]) - gets table of information about a function f as: nups, what, func, lastlinedefined, source, currentline, namewhat, linedefined, short_src
Template:UI Lua/id([thread,] nLevel, nLocal) - gets name and value of the variable at nLocal in stack nLevel
Template:UI Lua/id(obj) returns (mtable) - gets metatable for table or userdata (same as _G.getmetatable)
Template:UI Lua/id() - returns the registry table (not useable from UI)
Template:UI Lua/id(f, nUp) - gets name, value of upvalue nUp of function f. nil if no upvalue
Template:UI Lua/id([thread,] f, sMask [, count]) - sets function f as to be called for event sMask
Template:UI Lua/id([thread,] nLevel, nLocal, value) - assigns value to nLocal at stack nLevel. gets name, or nil if no nLocal. throws if no nLevel
Template:UI Lua/id(obj, mtable) returns (obj) - sets metatable for table or userdata (same as _G.setmetatable)
Template:UI Lua/id(f, nUp, value) - assigns value to upvalue nUp of function f. gets name or nil if no upvalue
Template:UI Lua/id([thread,] [sMessage [, nLevel]]) - gets string with a trace of call stack, starting at nLevel.

References added to debug. in WildStar

Template:UI Lua/id(any) returns (table) - stack frame of given function or stack level (same as _G.getfenv)
Template:UI Lua/id(function or nLevel, table) - sets table for stack frame for func or level (same as _G.setfenv)

Modules

The modules functions which are generally just a subset of the Lua stardard package library. Other than using the require keyword to access standard Carbine WS modules, the {{../api||Apollo}} library should be used instead for AddOns and Lua libraries, like {{../api||Apollo|RegisterAddon}} and {{../api||Apollo|RegisterPackage}}.

Template:UI Lua/id(name [, ···]) - sets this Lua chunk as named Lua module, in package.loaded[name] and _G[name]
Template:UI Lua/id(modname) - loads a module as reference in this Lua chunk, from package.loaded[name] or loader

Template:UI Lua/id

Template:UI Lua/id [string] = "\\\n;\n?\n!\n-" - list of chunk string seperators (undocumented)
Template:UI Lua/id [string] = ".\?.dll;!\?.dll;!\loadall.dll" - require path for C loader
Template:UI Lua/id [table] - table used by require for modules are already loaded
Template:UI Lua/id [table] - table used by require for how to load modules
Template:UI Lua/id(libname, sFunc) - loads and links a C Lua library
Template:UI Lua/id [string] = ".\?.lua;!\lua\?.lua;!\lua\?\init.lua;!\?.lua;!\?\init.lua" - require path for Lua loader
Template:UI Lua/id [table] - table to store loaders for specific modules
Template:UI Lua/id(module) - sets metatable on module so inherits from global environment. option to module()

See also

  • Lua - which has plenty of links to other reference material
  • [[../API types/]] - with a list of Lua types and 'psudo-types' used in WS