raw
Library containing functions for working with raw data. (ignoring metatables)
Modules
Fields
| Name | Type | Description |
|---|---|---|
setmetatable | debug.setmetatable | |
equal | rawequal | |
get | rawget | |
set | rawset |
Functions
raw.assert | Throws an error if the value is false or nil, otherwise returns all its arguments, like assert. |
raw.error | Throws an error with the specified message and level. |
raw.getmetatable | Returns the metatable of the given value, or nil if it doesn't have one. |
raw.index | Returns the value of the key in a table. |
raw.ipairs | Returns three values (an iterator function, the table t, and 0) so that the construction for i,v in ipairs(t) do body e… |
raw.len | Returns the length of the object value, without invoking the len metamethod. |
raw.pairs | If t has a metamethod pairs, calls it with t as argument and returns the first three results from the call. |
raw.print | Prints the given arguments to the console. |
raw.tonumber | If e has a metamethod tonumber, calls it with e and base as arguments and returns its result. |
raw.tostring | Receives a value of any type and converts it to a string in a human-readable format. |
#raw.assert
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.
local file = assert( open( path ), "cannot open '%s'", path )
assert( size >= 0, ValueError, "size must be positive, got %d", size )| Name | Type | Description |
|---|---|---|
value | T | The value to check. |
messageoptional | ( string | Error | ErrorClass )? | The error message, error object or error class. |
... | any | The message format arguments. |
| Type | Name | Description |
|---|---|---|
T | value | |
any | ... |
#raw.error
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.
| Name | Type | Description |
|---|---|---|
valueoptional | any | The error value to throw. |
stack_leveloptional | integer | The stack level to throw the error. |
#raw.getmetatable
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.
| Name | Type | Description |
|---|---|---|
object | any | The value to get the metatable of. |
| Type | Name | Description |
|---|---|---|
metatable | nil | metatable | The metatable of object, or nil if it has none. |
#raw.index
function raw.index(tbl: table, key: any): any
Returns the value of the key in a table.
| Name | Type | Description |
|---|---|---|
tbl | table | The table. |
key | any | The key. |
| Type | Name | Description |
|---|---|---|
any |
#raw.ipairs
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
for i,v in ipairs(t) do body endwill iterate over the key–value pairs (1,t[1]), (2,t[2]), ..., up to the first absent index.
View documents
| Name | Type | Description |
|---|---|---|
t | V[] |
| Type | Name | Description |
|---|---|---|
fun( table: V[], i: ( integer | nil ) ): integer | ||
V | ||
V[] | ||
integer | i |
#raw.len
function raw.len(value: table | string | any): integer
Returns the length of the object value, without invoking the __len metamethod.
| Name | Type | Description |
|---|---|---|
value | table | string | any |
| Type | Name | Description |
|---|---|---|
integer | length |
#raw.pairs
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
for k,v in pairs(t) do body endwill iterate over all key–value pairs of table t.
See function next for the caveats of modifying the table during its traversal.
View documents
| Name | Type | Description |
|---|---|---|
t | table<K, V> |
| Type | Name | Description |
|---|---|---|
fun( table: table<K, V>, index: ( K | nil ) ): K | ||
V | ||
table<K, V> |
#raw.print
function raw.print(...: any)
Alias of print.
Prints the given arguments to the console.
| Name | Type | Description |
|---|---|---|
... | any | The arguments to print. |
#raw.tonumber
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
| Name | Type | Description |
|---|---|---|
e | any | The value to convert to a number. |
baseoptional | numberbase | The number base, default is 10. |
| Type | Name | Description |
|---|---|---|
number | nil | x | The number value of e, or nil if e cannot be converted to a number. |
#raw.tostring
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.
| Name | Type | Description |
|---|---|---|
value | any | The value to convert to a string. |
| Type | Name | Description |
|---|---|---|
string | str | The string representation of value. |