From fcd4c9a267b407e653ed6b21ae87f219f3e4c4af Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 18 Aug 2026 16:39:37 +0200 Subject: Add global labels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are labels that are declared by prefixing a '#' symbol to the name, and it allows the label to be declared at the global scope instead of the current one. This is a feature which is not to be abused so to not make scopes pointless, but it can be quite handy with some optimizations while not abandoning scopes completely. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/object.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/xixanta/src/object.rs') diff --git a/lib/xixanta/src/object.rs b/lib/xixanta/src/object.rs index 6209afd..cc8908c 100644 --- a/lib/xixanta/src/object.rs +++ b/lib/xixanta/src/object.rs @@ -329,14 +329,22 @@ impl Context { /// Sets a value for an object identified by `id`. If `overwrite` is set to /// true, then this value will be set even if the id already existed, - /// otherwise it will return a ContextError + /// otherwise it will return a ContextError. If 'force_global' is set to + /// true, then the variable will be defined at the global context, not the + /// current one. pub fn set_variable( &mut self, id: &PString, object: &Object, overwrite: bool, + force_global: bool, ) -> Result<(), String> { - let scope_name = self.name().to_string(); + let scope_name = if force_global { + GLOBAL_CONTEXT + } else { + self.name() + } + .to_string(); let scope = self.map.get_mut(&scope_name).unwrap(); match scope.get_mut(&id.value) { -- cgit v1.2.3