Skip to main content

lje.env

Environment management, script context inspection, and global state control.

Functions

lje.env.get()

Returns the currently active global environment table, if one has been set via lje.env.set. Returns nothing if no environment is set.

Returns

TypeDescription
table | nil

The active environment table, or nil if none is set.

lje.env.set(env)

Sets the active global environment table. This environment is automatically applied to functions compiled via lje.func.compile. Replaces any previously set environment.

Parameters

NameTypeDescription
envtable

The table to use as the environment.

lje.env.current_script()

Returns the name of the currently executing LJE script, if any.

Returns

TypeDescription
string | nil

The script name, or nil if no script is currently active.

lje.env.current_script_path()

Returns the full path of the currently executing LJE script, if any.

Returns

TypeDescription
string | nil

The script path, or nil if no script is currently active.

lje.env.find_script_files(search_path)

Searches for files matching search_path relative to the current script's directory. Returns nil if no script is active.

Supports wildcard patterns, so if you wanted to find all files in detours/, you would do detours/*.

Parameters

NameTypeDescription
search_pathstring

A path pattern to search for, relative to the current script.

Returns

TypeDescription
table | nil

An array of matching file path strings, or nil if no script is active.

lje.env.is_lua_involved(frame_offset?)

Returns whether a Lua function is present in the call stack at or above the given frame offset.

Parameters

NameTypeDescription
frame_offset?integer

The frame level to start checking from. Defaults to 1.

Returns

TypeDescription
boolean

true if a Lua frame is involved at or above the offset.

lje.env.is_lje_involved(frame_offset?, max_depth?)

Returns whether an LJE frame is present in the call stack, starting from frame_offset and searching up to max_depth frames.

Parameters

NameTypeDescription
frame_offset?integer

The frame level to start checking from. Defaults to 1.

max_depth?integer

Maximum number of frames to search. Defaults to -1 (unlimited).

Returns

TypeDescription
boolean

true if an LJE frame is found within the search range.

lje.env.is_lje_frame(frame_offset?)

Returns whether the frame at exactly frame_offset is an LJE frame.

Parameters

NameTypeDescription
frame_offset?integer

The frame level to check. Defaults to 1.

Returns

TypeDescription
boolean

true if the specified frame is an LJE frame.

lje.env.disable_metatables()

Deprecated: Only here for compatibility - metatable remapping is automatic and does not require this function.

Globally disables metatable lookups. While disabled, __index, __newindex, and other metamethods will not be invoked. Re-enable with lje.env.enable_metatables.

lje.env.enable_metatables()

Deprecated: Only here for compatibility - metatable remapping is automatic and does not require this function.

Re-enables metatable lookups after they have been disabled.

lje.env.save_random_state()

Deprecated: LJE now uses a independent PRNG instance, this is no longer necessary or recommended.

Saves the current PRNG state. Use in combination with lje.env.restore_random_state to create a temporary branch of randomness that does not permanently affect the global PRNG sequence.

Note: Saving and immediately restoring erases all randomness that occurred in between — subsequent calls will produce the same sequence. To avoid this, only save/restore at most once per logical frame, or re-seed the PRNG manually afterward.

lje.env.restore_random_state()

Deprecated: LJE now uses a independent PRNG instance, this is no longer necessary or recommended.

Restores the PRNG state previously saved by lje.env.save_random_state.

lje.env.remap_metatable(type_name, replacement)

Replaces the metatable used for a given Lua type name with replacement. Affects all future metatable lookups for that type.

Parameters

NameTypeDescription
type_namestring

The name of the type whose metatable should be remapped.

replacementtable

The new metatable to use.

lje.env.auth_metatable(metatable)

Marks a metatable as authorized, allowing it to bypass LJE's metatable access restrictions.

Parameters

NameTypeDescription
metatabletable

The metatable to authorize.

lje.env.show_special_frames(show)

Controls whether special (internal LJE) frames are visible in stack introspection. Useful when debugging inter-LJE interactions.

Parameters

NameTypeDescription
showboolean

true to make special frames visible, false to hide them.