Skip to main content

luaur_analysis/methods/
stringifier_state_emit_level.rs

1//! Node: `cxx:Method:Luau.Analysis:Analysis/src/ToString.cpp:262:stringifier_state_emit_level`
2//! Source: `Analysis/src/ToString.cpp:262-278` (hand-ported)
3
4use crate::records::scope::Scope;
5use crate::records::stringifier_state::StringifierState;
6use alloc::format;
7use alloc::sync::Arc;
8
9impl StringifierState {
10    /// C++ `void emitLevel(Scope* scope)`.
11    pub fn emit_level(&mut self, scope: *mut Scope) {
12        unsafe {
13            let mut count: usize = 0;
14            let mut s = scope as *const Scope;
15            while !s.is_null() {
16                count += 1;
17                s = match &(*s).parent {
18                    Some(p) => Arc::as_ptr(p),
19                    None => core::ptr::null(),
20                };
21            }
22
23            self.emit(&count);
24
25            if luaur_common::FInt::DebugLuauVerboseTypeNames.get() >= 3 {
26                self.emit("-");
27                // snprintf(buffer, 16, "0x%x", uint32_t(intptr_t(scope) & 0xFFFFFF))
28                let v = (scope as usize as u32) & 0xFFFFFF;
29                let buffer = format!("0x{:x}", v);
30                self.emit(buffer.as_str());
31            }
32        }
33    }
34}