Skip to main content

luaur_analysis/methods/
stringifier_state_stringifier_state.rs

1//! Node: `cxx:Method:Luau.Analysis:Analysis/src/ToString.cpp:178:stringifier_state_stringifier_state`
2//! Source: `Analysis/src/ToString.cpp:178-190` (hand-ported)
3
4use crate::records::set::Set;
5use crate::records::stringifier_state::StringifierState;
6use crate::records::to_string_options::ToStringOptions;
7use crate::records::to_string_result::ToStringResult;
8use alloc::string::String;
9use luaur_common::records::dense_hash_map::DenseHashMap;
10use luaur_common::records::dense_hash_set::DenseHashSet;
11
12impl StringifierState {
13    /// C++ `StringifierState(ToStringOptions& opts, ToStringResult& result)`.
14    /// The C++ reference members are raw pointers in the record; callers keep
15    /// `opts`/`result` alive for the state's lifetime (as in C++).
16    pub fn stringifier_state_stringifier_state(
17        opts: *mut ToStringOptions,
18        result: *mut ToStringResult,
19    ) -> Self {
20        unsafe {
21            let o = &*opts;
22            let mut state = StringifierState {
23                opts,
24                result,
25                cycle_names: DenseHashMap::new(core::ptr::null()),
26                cycle_tp_names: DenseHashMap::new(core::ptr::null()),
27                seen: Set::new(core::ptr::null_mut()),
28                // `$$$` is the usedNames tombstone: not a valid name syntactically
29                // and short for string comparison reasons.
30                used_names: DenseHashSet::new(String::from("$$$")),
31                indentation: 0,
32                exhaustive: o.exhaustive,
33                ignore_synthetic_name: o.ignore_synthetic_name,
34                previous_name_index: 0,
35            };
36
37            for (_k, v) in o.name_map.types.iter() {
38                state.used_names.insert(v.clone());
39            }
40            for (_k, v) in o.name_map.type_packs.iter() {
41                state.used_names.insert(v.clone());
42            }
43
44            state
45        }
46    }
47}