Skip to main content

luaur_analysis/methods/
frontend_apply_builtin_definition_to_environment.rs

1use crate::records::frontend::Frontend;
2use crate::records::global_types::GlobalTypes;
3use alloc::string::String;
4use luaur_common::macros::luau_assert::LUAU_ASSERT;
5
6impl Frontend {
7    pub fn apply_builtin_definition_to_environment(
8        &mut self,
9        environment_name: String,
10        definition_name: String,
11    ) {
12        LUAU_ASSERT!(self.builtin_definitions.contains_key(&definition_name));
13
14        if self.builtin_definitions.contains_key(&definition_name) {
15            let applicator = self
16                .builtin_definitions
17                .get(&definition_name)
18                .unwrap()
19                .clone();
20            let environment_scope = self.get_environment_scope(environment_name);
21            // C++: builtinDefinitions[definitionName](*this, globals, getEnvironmentScope(...));
22            // The C++ passes both *this and the `globals` member by mutable reference at the
23            // same call; Rust forbids aliasing &mut self with &mut self.globals, so split the
24            // borrow through a raw pointer to the `globals` field (the applicator never
25            // re-enters `self.globals` through `self`, matching C++ semantics).
26            let globals_ptr: *mut GlobalTypes = &mut self.globals;
27            applicator(self, unsafe { &mut *globals_ptr }, environment_scope);
28        }
29    }
30}