diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-08-18 16:39:37 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-08-18 16:39:37 +0200 |
| commit | fcd4c9a267b407e653ed6b21ae87f219f3e4c4af (patch) | |
| tree | 0b5f3e9bf99ab7377fa0bb6d204661ac8fbe3380 /lib/xixanta/src/object.rs | |
| parent | d479b0fbd3778f5b6fc8b63f46aa0c5364e4fe7e (diff) | |
| download | tools.nes-fcd4c9a267b407e653ed6b21ae87f219f3e4c4af.tar.gz tools.nes-fcd4c9a267b407e653ed6b21ae87f219f3e4c4af.zip | |
Add global labels
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à <mssola@mssola.com>
Diffstat (limited to 'lib/xixanta/src/object.rs')
| -rw-r--r-- | lib/xixanta/src/object.rs | 12 |
1 files changed, 10 insertions, 2 deletions
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) { |
