> For the complete documentation index, see [llms.txt](https://edwn.gitbook.io/impulse/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://edwn.gitbook.io/impulse/enviornment/globals/lua-globals.md).

# Lua globals

## assert

```lua
assert(value: boolean, error_message: string) -> nil
```

Throws an error if the provided value is `false` or `nil`, stopping execution and displaying the provided error message.

## error

```lua
error(message: string, level: number) -> nil
```

Immediately halts execution and throws an error with the given message and optional stack level.

## gcinfo

```lua
gcinfo() -> number
```

Returns the current memory usage in kilobytes, providing insight into Lua's garbage collection.

## getmetatable

```lua
getmetatable(t: table) -> table | nil
```

Retrieves the metatable of the given table, or `nil` if no metatable exists.

## ipairs

```lua
ipairs(t: table) -> function, table, number
```

Returns an iterator function for sequentially iterating over an array-like table in order.

## newproxy

```lua
newproxy(add_metatable: boolean) -> userdata
```

Creates a blank userdata object, optionally with a metatable for custom behavior.

## next

```lua
next(t: table, last_key: any) -> any, any
```

Returns the next key-value pair in a table, allowing iteration when used in a loop.

## pairs

```lua
pairs(t: table) -> function, table
```

Returns an iterator function for traversing all key-value pairs in a table, including non-sequential keys.

## pcall

```lua
pcall(func: function, ...: any) -> boolean, any
```

Calls a function safely, returning `true` and the result if successful, or `false` and an error message if an error occurs.

## print ⚠️

```lua
print(...: any) -> nil
```

Outputs the provided values to the console for debugging or display purposes.

{% hint style="warning" %}
`print` is overwritten by Impulse, go [here](/impulse/enviornment/globals/impulse-globals.md#print).
{% endhint %}

## rawequal

```lua
rawequal(v1: any, v2: any) -> boolean
```

Compares two values for equality, ignoring metamethods such as `__eq`.

## rawget

```lua
rawget(t: table, index: any) -> any
```

Directly retrieves a value from a table, bypassing any `__index` metamethods.

## rawlen

```lua
rawlen(t: table) -> number
```

Returns the length of a table or string without invoking metamethods.

## rawset

```lua
rawset(t: table, index: any, value: any) -> nil
```

Directly assigns a value to a table, bypassing any `__newindex` metamethods.

## require

```lua
require(module: string | number) -> any
```

Loads and runs a module script, returning its result if it has already been executed.

## select

```lua
select(index: number, ...: any) -> any
```

Returns all arguments after the specified index, or the total argument count if the index is `"#"`.

## setmetatable

```lua
setmetatable(t: table, new_meta: table) -> table
```

Assigns a new metatable to the given table, enabling custom behaviors like operator overloading.

## tonumber

```lua
tonumber(arg: any, base: number) -> number | nil
```

Converts a value to a number, optionally using a specified base, or returns `nil` if conversion fails.

## tostring

```lua
tostring(value: any) -> string
```

Converts a value into a string representation, typically used for debugging or display.

## type

```lua
type(value: any) -> string
```

Returns a string representing the type of the given value, such as `number`, `string`, or `table`.

## unpack

```lua
unpack(list: table, i: number, j: number) -> ...any
```

Returns multiple values from a table, from index `i` to `j`, effectively "unpacking" them.

## xpcall

```lua
xpcall(func: function, err: function, ...: any) -> boolean, any
```

Similar to [pcall](#pcall), but allows for a custom error handler function to process errors before they are returned.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://edwn.gitbook.io/impulse/enviornment/globals/lua-globals.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
