# 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: 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://lua2.fatality.win/api/types/ptr.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.
