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_IDSIZEin upstreamluaconf.h. - MAX_
NUMBER_ 2_ STR - Maximum size of a number-to-string conversion buffer.
Accommodates both
%.14gfloat formatting and%lldinteger 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 slotres. Falls back to a binary tag-method if raw arithmetic is not possible. - ceil_
log2 - Computes
ceil(log2(x)); returns the minimumksuch that2^k >= x. - chunk_
id - Fills
outwith a human-readable identifier derived fromsourceand 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
cis a valid hex digit. - num_
to_ string - Converts a numeric
LuaValueto an internedLuaString, returning aGcRef<LuaString>handle. Callers are responsible for updating theLuaValue(or stack slot) withLuaValue::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
resand returnstrueon success,falseif the operation cannot be performed with the given types (caller should invoke a metamethod instead). - str2num
- Tries to convert the byte string
sto a Lua number (integer first, then float). Writes the result tooand returnsconsumed_bytes + 1on success (matching the C convention of including the null terminator in the count), or0on failure. - utf8_
esc - Encodes Unicode codepoint
xas UTF-8 intobuff(filled backwards from indexUTF8_BUF_SZ - 1). Returns the number of bytes written. The valid bytes occupybuff[UTF8_BUF_SZ - n .. UTF8_BUF_SZ].