Skip to content

ax.type

Source: gamemode/framework/libraries/sh_type.lua

The type library provides utilities for type detection, sanitization, and formatting.

Documented functions: 3

Functions


ax.type:Detect(value)

Detects the type ID of a given value. Automatically determines the appropriate type constant for any Lua value. Useful for dynamic type checking and validation.

Realm: shared

Parameters

Name Type Description
value any The value to detect the type of

Returns

  • number|nil: The detected type ID, or nil if the type could not be determined

Usage

local typeID = ax.type:Detect("example") -- returns ax.type.string
local typeID = ax.type:Detect(Vector(1,2,3)) -- returns ax.type.vector

ax.type:Format(typeID)

Formats a type ID into a human-readable string. Converts type constants into user-friendly names for display purposes.

Realm: shared

Parameters

Name Type Description
typeID number The type ID to format

Returns

  • string: The formatted type name

Usage

local typeName = ax.type:Format(ax.type.color) -- returns "Color"
local typeName = ax.type:Format(ax.type.player) -- returns "Player"

ax.type:Sanitise(typeID, value)

Sanitizes a value to match the specified type ID. Converts and validates values to ensure they conform to the expected type. Returns nil if the value cannot be sanitized to the target type.

Realm: shared

Parameters

Name Type Description
typeID number The type ID to sanitize the value to
value any The value to sanitize

Returns

  • any: The sanitized value, or nil if sanitization failed

Usage

local sanitizedValue = ax.type:Sanitise(ax.type.number, "123") -- returns 123
local player = ax.type:Sanitise(ax.type.player, "John") -- returns player entity or nil