Skip to main content

Module string

Module string 

Source
Expand description

String table and interned-string operations — port of lstring.c + lstring.h.

Provides two key abstractions:

  • LuaStringImpl: the Lua string value, stored as a reference-counted byte slice. Short strings (<= MAX_SHORT_LEN bytes) are interned in the process-global StringPool; long strings are heap-allocated on each creation and never interned.

  • StringPool: the intern table for short strings, stored on GlobalState. Replaces the C stringtable struct, which used an open-addressing hash table with intrusive chaining through TString.u.hnext. In Rust the intrusive chain is dropped; a HashMap provides O(1) lookup and automatic rehashing. See PORT NOTE on StringPool for the full rationale.

The lstring.h header is merged into this module per PORTING.md §1.

§C source files

  • reference/lua-5.4.7/src/lstring.c (275 lines, 15 functions)
  • reference/lua-5.4.7/src/lstring.h (57 lines; merged here)

Structs§

LuaStringImpl
A Lua string: an immutable, reference-counted byte sequence.
LuaUserDataImpl
Full userdata: a GC-tracked object carrying a raw byte payload plus optional Lua user values and an optional metatable.
StringPool
Intern table for short Lua strings. Lives on GlobalState.

Enums§

StringKind
Whether a Lua string is short (interned) or long (not interned).