Skip to main content

lje.util

Miscellaneous utility functions for bytecode inspection, stack introspection, and table creation.

Functions

lje.util.get_bytecode_hash(fn)

Returns a FNV-1a hash of the bytecode of a Lua function. Useful as a stable identity for a function's compiled bytecode — two functions with identical source compiled identically will produce the same hash.

Parameters

NameTypeDescription
fnfunction

Must be a Lua function, not a C function.

Returns

TypeDescription
integer

A 32-bit hash of the function's bytecode.

Errors

  • Argument 1 must be a Lua function (not a C function).

lje.util.get_call_stack()

Returns the current call stack as an array of frame descriptor tables. Each entry contains a level (1-based integer), a type ("lua" or "c"), and a func (the function at that level). Lua frames additionally include a chunkname field.

Returns

TypeDescription
table

An array of frame descriptor tables, ordered from innermost to outermost. Each entry has: level (integer), type ("lua" or "c"), func (function), and optionally chunkname (string, Lua frames only).

lje.util.get_registry()

Returns the Lua registry table (LUA_REGISTRYINDEX). Useful for inspecting or manipulating registry-stored references.

Returns

TypeDescription
table

The Lua registry table.

lje.util.set_push_string_callback(fn)

Registers a Lua function to be called whenever LJE pushes a string value. The function is automatically marked as special. Only one callback can be active at a time.

Parameters

NameTypeDescription
fnfunction

Must be a Lua function, not a C function.

Errors

  • Argument 1 must be a Lua function (not a C function).

lje.util.set_script_hook_callback(fn)

Registers a Lua function to be called on script hook events. The function is automatically marked as special. Only one callback can be active at a time.

Parameters

NameTypeDescription
fnfunction

Must be a Lua function, not a C function.

Errors

  • Argument 1 must be a Lua function (not a C function).

lje.util.create_table(narr?, nrec?)

Creates a new table with pre-allocated space. Equivalent to lua_createtable. Useful for avoiding rehashing overhead when the approximate size of the table is known in advance.

Parameters

NameTypeDescription
narr?integer

Expected number of array-part entries. Defaults to 0.

nrec?integer

Expected number of hash-part entries. Defaults to 0.

Returns

TypeDescription
table

A new empty table with the requested pre-allocated capacity.