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
| Name | Type | Description |
|---|---|---|
fn | function | Must be a Lua function, not a C function. |
Returns
| Type | Description |
|---|---|
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
| Type | Description |
|---|---|
table | An array of frame descriptor tables, ordered from innermost to outermost. Each entry has: |
lje.util.get_registry()
Returns the Lua registry table (LUA_REGISTRYINDEX). Useful for inspecting or manipulating registry-stored references.
Returns
| Type | Description |
|---|---|
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
| Name | Type | Description |
|---|---|---|
fn | function | 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
| Name | Type | Description |
|---|---|---|
fn | function | 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
| Name | Type | Description |
|---|---|---|
narr? | integer | Expected number of array-part entries. Defaults to |
nrec? | integer | Expected number of hash-part entries. Defaults to |
Returns
| Type | Description |
|---|---|
table | A new empty table with the requested pre-allocated capacity. |