> ## Documentation Index
> Fetch the complete documentation index at: https://gluals.arnux.net/llms.txt
> Use this file to discover all available pages before exploring further.

# @self_class_name

> Mark a method that returns the class name of the object it is called on.

> [!NOTE]
>
> This annotation is intended for complex cases and is primarily designed to be used by the built-in annotations.

## Overview

`self_class_name` marks a colon method such as `Entity:GetClass` that returns the class name of the object it is called on. When you compare that name with a class, or pass it to a base test such as `scripted_ents.IsBasedOn`, GLuaLS narrows the object to that class.

Other methods that return a string, like `ent:GetOwnerClass()`, do not narrow the object.

The official annotations already mark `Entity:GetClass`.

***

## Syntax

```lua theme={null}
---@return string
---@[self_class_name]
```

Put it after the `@return` line. The method must take no arguments.

***

## Example

```lua theme={null}
---@return string
---@[self_class_name]
function Entity:GetClass() end
```

```lua theme={null}
---@param ent Entity
local function Use(ent)
    if ent:GetClass() == "mech_walker" then
        ent:Stomp() -- ent is a mech_walker here
    end

    if scripted_ents.IsBasedOn(ent:GetClass(), "mech_base") then
        ent:Disposition() -- ent is a mech_base here
    end
end
```

When GLuaLS cannot tell what type the object has, it narrows if any method with that name carries the attribute.

***

## Keep it narrow

Only use it on a method that returns the object's own Lua class name. `Panel:GetClassName` returns the engine panel class, such as `Label`, not the Lua class, so it is not marked.

***

## See also

* [`@call_arg`](https://gluals.arnux.net/annotations/call-arg): marks the class name and base arguments of `IsBasedOn`
* [`@self_guard`](https://gluals.arnux.net/annotations/self-guard): a method that proves the object it is called on is valid


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.