lje (Lua extensions)
Lua-defined extensions added to `lje` and the safe environment during preinit.
Constants
| Name | Type | Description |
|---|---|---|
_G | table | A reference to the original, unmodified global environment. Exposed in the safe environment so scripts can access globals that may have been shadowed or overwritten. |
_L | table | A circular reference to the safe environment itself. Useful for passing the safe environment to functions that need an explicit reference to it. |
cloned_mts | table | A map of cloned metatables, keyed by type name (e.g. |
cloned_basemts | table | A map of cloned base metatables for primitive types, keyed by type name. Currently contains |
insecure_mts | table | Stores the original (uncloned) base metatables when |
lje.includeCache | table | A per-script cache used by |
Functions
lje.detour(origFn, detourFn)
Creates a detour by marking detourFn as special and spoofing it to appear as origFn in debug introspection. If origFn is a C or fast function, JIT compilation is disabled on detourFn to prevent crashes.
Parameters
| Name | Type | Description |
|---|---|---|
origFn | function | The original function being detoured. Determines whether JIT must be disabled. |
detourFn | function | Your replacement function. Will be marked special and spoofed to look like |
Returns
| Type | Description |
|---|---|
function |
|
lje.require(path)
A cached version of lje.include. The first call for a given path within a script context executes the file and caches the result. Subsequent calls return the cached value immediately. Must be called within an active script context.
Parameters
| Name | Type | Description |
|---|---|---|
path | string | Path to the file to include, relative to the current script. |
Returns
| Type | Description |
|---|---|
any | The return value of the included file, or the cached result from a prior call. |
lje.con_printf(fmt, ...?)
A string.format-style console print with inline ANSI color support. Wrap text in $colorName{...} to colorize it.
Supported colors: black, red, green, yellow, blue, magenta, cyan, white, default.
Example:
lje.con_printf("$red{Error}: %s", message)
Parameters
| Name | Type | Description |
|---|---|---|
fmt | string | A |
...? | any | Format arguments, passed to |
lje.get_global(...)
Safely traverses the original global environment (_G) using rawget at each step, following a variadic path of keys. Returns nil at the first missing or non-table intermediate value.
Example:
local fn = lje.get_global("hook", "Add")
Parameters
| Name | Type | Description |
|---|---|---|
... | string | A sequence of keys forming the path to traverse in |
Returns
| Type | Description |
|---|---|
any | nil | The value at the end of the path, or |
lje.get_global_static(paths, count)
Same behavior as lje.get_global but avoids the vararg allocation. Pass a pre-built table of keys and its length. Prefer this in hot paths where allocation matters.
Example:
local path = {"hook", "Add"}
local fn = lje.get_global_static(path, 2)
Parameters
| Name | Type | Description |
|---|---|---|
paths | table | An array of string keys forming the traversal path. Avoid creating this table dynamically, as that defeats the purpose of this function. |
count | integer | The number of keys in |
Returns
| Type | Description |
|---|---|
any | nil | The value at the end of the path, or |
lje.use_safe_basemts()
Swaps in the cloned base metatables for primitive types (currently string). The original metatables are saved in insecure_mts so they can be restored. Call lje.restore_basemts when done.
lje.restore_basemts()
Restores the original base metatables saved by lje.use_safe_basemts. Has no effect if use_safe_basemts was not previously called.