Skip to main content

parse

Function parse 

Source
pub fn parse(
    state: &mut LuaState,
    dyd: DynData,
    z: &mut ZIO,
    name: &[u8],
    firstchar: i32,
) -> Result<Box<LuaProto>, LuaError>
Expand description

Top-level entry point: parses a whole chunk and returns the prototype of its main function. The caller wraps this Box<LuaProto> into a closure and hands it to the GC; that boundary is the public contract of this crate.

§Precondition — GC must be stopped for the whole parse window

The parser holds untraced references to GC-managed objects for the duration of a parse: interned name/string handles, the half-built Box<LuaProto>, long-string anchors, and — for <const> folding — the value stored in a VarDesc::const_val / ExprPayload::const_snapshot (which may be an interned string). None of these are reachable from a GC root while parsing, so a collection cycle during parse could free a live constant and produce a use-after-free. The supported entry points satisfy this: the loader stops the collector across the entire production parse window (do_.rs f_parser), and explicit collectgarbage requests early-return while internally stopped. A direct caller of this function that has NOT stopped the GC violates the contract — this is a pre-existing whole-parser requirement (the constant table has always needed it), not specific to <const> folding.