luaur-common 0.1.2

Foundational data structures and flags for the luaur Luau-in-Rust toolchain.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//! Source: `Common/src/TimeTrace.cpp:109-113` (hand-ported)
//! C++ `getGlobalContext()` returns a process-wide `shared_ptr` singleton:
//! ```cpp
//! static std::shared_ptr<GlobalContext> context = std::shared_ptr<GlobalContext>{new GlobalContext};
//! return context;
//! ```
use crate::records::global_context::GlobalContext;
use std::sync::{Arc, OnceLock};

pub fn get_global_context() -> Arc<GlobalContext> {
    static CONTEXT: OnceLock<Arc<GlobalContext>> = OnceLock::new();
    CONTEXT
        .get_or_init(|| Arc::new(GlobalContext::new()))
        .clone()
}