luaur-common 0.1.3

Foundational data structures and flags for the luaur Luau-in-Rust toolchain.
Documentation
//! Source: `Common/include/Luau/TimeTrace.h:148-159` (hand-ported)
//! C++:
//! ```cpp
//! explicit Scope(uint16_t token) : context(getThreadContext())
//! {
//!     if (!FFlag::DebugLuauTimeTracing) return;
//!     context.eventEnter(token);
//! }
//! ```
use crate::functions::get_thread_context::get_thread_context;
use crate::records::scope::Scope;
use crate::FFlag::DebugLuauTimeTracing;

impl Scope {
    pub fn scope(token: u16) -> Self {
        let context = get_thread_context();
        let scope = Scope {
            context: context as *mut _,
        };

        if !DebugLuauTimeTracing.get() {
            return scope;
        }

        context.event_enter_u16(token);
        scope
    }
}