dreamworkAPI
Ctrl K
GitHub
libraryDocs / raw

raw

librarysharedmenusource

Library containing functions for working with raw data. (ignoring metatables)

Modules

Fields

NameTypeDescription
setmetatabledebug.setmetatable
equalrawequal
getrawget
setrawset

Functions

raw.assertThrows an error if the value is false or nil, otherwise returns all its arguments, like assert.
raw.errorThrows an error with the specified message and level.
raw.getmetatableReturns the metatable of the given value, or nil if it doesn't have one.
raw.indexReturns the value of the key in a table.
raw.ipairsReturns three values (an iterator function, the table t, and 0) so that the construction for i,v in ipairs(t) do body e…
raw.lenReturns the length of the object value, without invoking the len metamethod.
raw.pairsIf t has a metamethod pairs, calls it with t as argument and returns the first three results from the call.
raw.printPrints the given arguments to the console.
raw.tonumberIf e has a metamethod tonumber, calls it with e and base as arguments and returns its result.
raw.tostringReceives a value of any type and converts it to a string in a human-readable format.

#raw.assert

sharedmenusource
function raw.assert(value: T, message?: ( string | Error | ErrorClass )?, ...: any): T, any

Alias of assert.

Throws an error if the value is false or nil, otherwise returns all its arguments, like assert.

The message can be:

  • nil, which throws "assertion failed!";
  • a string, formatted with the remaining arguments when there are any;
  • an Error, which is thrown as is;
  • an error class, created with the string formatted from the remaining arguments.
lua
local file = assert( open( path ), "cannot open '%s'", path )
assert( size >= 0, ValueError, "size must be positive, got %d", size )
Parameters
NameTypeDescription
valueTThe value to check.
messageoptional( string | Error | ErrorClass )?The error message, error object or error class.
...anyThe message format arguments.
Returns
TypeNameDescription
Tvalue
any...

#raw.error

sharedmenusource
function raw.error(value?: any, stack_level?: integer)

Alias of error.

Throws an error with the specified message and level.

An Error that already has a call stack is rethrown as is; if it was captured in another thread (e.g. inside a resumed coroutine) the frames leading here are added below it. Call Error:reset before throwing the same object again to capture a fresh stack.

Values that are neither errors nor strings (signals like ACTION_CANCEL) are thrown as is inside protected calls and coroutines, so they keep their identity.

Parameters
NameTypeDescription
valueoptionalanyThe error value to throw.
stack_leveloptionalintegerThe stack level to throw the error.

#raw.getmetatable

sharedmenunodiscardsource
function raw.getmetatable(object: any): metatable | nil

Alias of debug.getmetatable.

Returns the metatable of the given value, or nil if it doesn't have one.

Unlike the standard getmetatable, this ignores the __metatable field, so it can reach metatables that are protected from normal code.

View documents

Parameters
NameTypeDescription
objectanyThe value to get the metatable of.
Returns
TypeNameDescription
metatable | nilmetatableThe metatable of object, or nil if it has none.

#raw.index

sharedmenunodiscardsource
function raw.index(tbl: table, key: any): any

Returns the value of the key in a table.

Parameters
NameTypeDescription
tbltableThe table.
keyanyThe key.
Returns
TypeNameDescription
any

#raw.ipairs

sharedmenunodiscardsource
function raw.ipairs(t: V[]): (fun( table: V[], i: ( integer | nil ) ): integer), V, V[], integer

Alias of ipairs.

Returns three values (an iterator function, the table t, and 0) so that the construction

lua
    for i,v in ipairs(t) do body end

will iterate over the key–value pairs (1,t[1]), (2,t[2]), ..., up to the first absent index.

View documents

Parameters
NameTypeDescription
tV[]
Returns
TypeNameDescription
fun( table: V[], i: ( integer | nil ) ): integer
V
V[]
integeri

#raw.len

sharedmenunodiscardsource
function raw.len(value: table | string | any): integer

Returns the length of the object value, without invoking the __len metamethod.

View documents

Parameters
NameTypeDescription
valuetable | string | any
Returns
TypeNameDescription
integerlength

#raw.pairs

sharedmenunodiscardsource
function raw.pairs(t: table<K, V>): (fun( table: table<K, V>, index: ( K | nil ) ): K), V, table<K, V>

Alias of pairs.

If t has a metamethod __pairs, calls it with t as argument and returns the first three results from the call.

Otherwise, returns three values: the next function, the table t, and nil, so that the construction

lua
    for k,v in pairs(t) do body end

will iterate over all key–value pairs of table t.

See function next for the caveats of modifying the table during its traversal.

View documents

Parameters
NameTypeDescription
ttable<K, V>
Returns
TypeNameDescription
fun( table: table<K, V>, index: ( K | nil ) ): K
V
table<K, V>

#raw.print

sharedmenusource
function raw.print(...: any)

Alias of print.

Prints the given arguments to the console.

Parameters
NameTypeDescription
...anyThe arguments to print.

#raw.tonumber

sharedmenunodiscardsource
function raw.tonumber(e: any, base?: numberbase): number | nil

Alias of tonumber.

If e has a metamethod __tonumber, calls it with e and base as arguments and returns its result.

When called with no base, tonumber tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, it returns fail.

The conversion of strings can result in integers or floats, according to the lexical conventions of Lua (see §3.1). The string may have leading and trailing spaces and a sign.

View documents

Parameters
NameTypeDescription
eanyThe value to convert to a number.
baseoptionalnumberbaseThe number base, default is 10.
Returns
TypeNameDescription
number | nilxThe number value of e, or nil if e cannot be converted to a number.

#raw.tostring

sharedmenunodiscardsource
function raw.tostring(value: any): string

Alias of tostring.

Receives a value of any type and converts it to a string in a human-readable format.

If the metatable of v has a __tostring field, then tostring calls the corresponding value with v as argument, and uses the result of the call as its result.

Otherwise, if the metatable of v has a __name field with a string value, tostring may use that string in its final result.

For complete control of how numbers are converted, use string.format.

View documents

Parameters
NameTypeDescription
valueanyThe value to convert to a string.
Returns
TypeNameDescription
stringstrThe string representation of value.
Generated from the dreamwork meta branch.