Skip to main content

Module object

Module object 

Source
Expand description

Generic functions over Lua objects.

Ported from reference/lua-5.4.7/src/lobject.c (602 lines, ~20 functions).

Enums§

FmtArg
Typed format argument for push_vfstring.

Constants§

LUA_ID_SIZE
Maximum length of a chunk source identifier in error messages. Matches LUA_IDSIZE in upstream luaconf.h.
MAX_NUMBER_2_STR
Maximum size of a number-to-string conversion buffer. Accommodates both %.14g float formatting and %lld integer formatting.
UTF8_BUF_SZ
Buffer size (bytes) for UTF-8 encoding; encoded backwards into this buffer.

Functions§

arith
Performs arithmetic for opcode op, writing the result to the stack slot res. Falls back to a binary tag-method if raw arithmetic is not possible.
ceil_log2
Computes ceil(log2(x)); returns the minimum k such that 2^k >= x.
chunk_id
Fills out with a human-readable identifier derived from source and returns the number of bytes written (not including any null terminator).
hex_value
Converts a hexadecimal digit byte to its numeric value (0–15). Caller must ensure c is a valid hex digit.
num_to_string
Converts a numeric LuaValue to an interned LuaString, returning a GcRef<LuaString> handle. Callers are responsible for updating the LuaValue (or stack slot) with LuaValue::Str(s).
push_fstring
Variadic entry point; delegates to push_vfstring.
push_vfstring
Builds a formatted Lua string from a format byte string and structured arguments, pushes it onto the stack, and returns the top-of-stack value.
raw_arith
Attempts raw (no-metamethod) arithmetic on two Lua values. Writes the result to res and returns true on success, false if the operation cannot be performed with the given types (caller should invoke a metamethod instead).
str2num
Tries to convert the byte string s to a Lua number (integer first, then float). Writes the result to o and returns consumed_bytes + 1 on success (matching the C convention of including the null terminator in the count), or 0 on failure.
utf8_esc
Encodes Unicode codepoint x as UTF-8 into buff (filled backwards from index UTF8_BUF_SZ - 1). Returns the number of bytes written. The valid bytes occupy buff[UTF8_BUF_SZ - n .. UTF8_BUF_SZ].