Skip to main content

luaur_web/records/
demo_config_resolver.rs

1//! Port of `DemoConfigResolver : Luau::ConfigResolver` (`CLI/src/Web.cpp:49-62`).
2//!
3//! The luau.org/demo config resolver. Defaults to `Mode::Nonstrict` so each
4//! script's own mode comment governs (a deliberate playground deviation from
5//! `Web.cpp`'s hard `Strict`; see `methods/demo_config_resolver_demo_config_resolver`).
6//! Like the
7//! analysis `ConfigResolver` (a struct with a fn-pointer vtable slot for the
8//! single pure virtual `getConfig`), this concrete subclass is `#[repr(C)]` with
9//! `base: ConfigResolver` first so a `*const ConfigResolver` (the vtable
10//! receiver) can be cast back to `*const DemoConfigResolver` to reach
11//! `default_config`.
12//!
13//! C++ member: `Luau::Config defaultConfig;`.
14
15use luaur_analysis::records::config_resolver::ConfigResolver;
16use luaur_analysis::records::type_check_limits::TypeCheckLimits;
17use luaur_config::records::config::Config;
18use luaur_config::type_aliases::module_name::ModuleName;
19
20#[repr(C)]
21#[derive(Debug)]
22pub struct DemoConfigResolver {
23    pub base: ConfigResolver,
24    pub default_config: Config,
25}
26
27/// `const Config& getConfig(const ModuleName&, const TypeCheckLimits&) const` thunk.
28///
29/// # Safety
30/// `this` must point at the `base` subobject of a live `DemoConfigResolver`.
31pub(crate) unsafe fn demo_config_resolver_get_config_thunk(
32    this: *const ConfigResolver,
33    name: *const ModuleName,
34    limits: *const TypeCheckLimits,
35) -> *const Config {
36    let this = this as *const DemoConfigResolver;
37    (*this).get_config(&*name, &*limits) as *const Config
38}