> For the complete documentation index, see [llms.txt](https://lua2.fatality.win/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lua2.fatality.win/api/types/ptr.md).

# Ptr

This type is a literal pointer.

To preserve interoperability with C++, several functions return `void*` as the type, which then get converted to `light_userdata`. Since you can’t directly cast FFI types to `light_userdata`, we’ve introduced a specialized type helping with this conversion.

Before you convert your pointer to one that is supported by the API, you need to cast it to `uintptr_t`. This can be done in the following manner:

```lua
local ptr_num = ffi.cast('uintptr_t', ptr_cdata);
```

Then, you can use the cast value in this type's constructor.

## \_\_call﻿ <a href="#call" id="call"></a>

[<kbd><mark style="background-color:purple;">**Constructor**<mark style="background-color:purple;"></kbd>](#user-content-fn-1)[^1]

Converts a number to pointer.

**Arguments**

| Name  | Type  | Description         |
| ----- | ----- | ------------------- |
| `num` | `int` | Pointer, as number. |

**Returns**

| Type  | Description                   |
| ----- | ----------------------------- |
| `Ptr` | Pointer, as `light_userdata`. |

**Example**

```lua
-- cast to number first
local ptr_num = ffi.cast('uintptr_t', ptr_cdata);

-- then cast to light_userdata
local ptr_ld = Ptr(ptr_num);
```

[^1]: This is a constructor definition for this type.


---

# 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, and the optional `goal` query parameter:

```
GET https://lua2.fatality.win/api/types/ptr.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
