diff options
Diffstat (limited to 'src/macro_processor')
-rw-r--r-- | src/macro_processor/macro_processor.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/macro_processor/macro_processor.rs b/src/macro_processor/macro_processor.rs index ba28b15..612d2c5 100644 --- a/src/macro_processor/macro_processor.rs +++ b/src/macro_processor/macro_processor.rs @@ -412,6 +412,32 @@ fn smp_builtin_array_each( Ok(out) } +fn smp_builtin_array_size( + smp: &mut MacroProcessor, + macro_name: &str, + args: &mut [String], +) -> Result<String, SMPError> { + let Some(macro_body) = smp.macros.get(&args[0]) else { + smp.warnings + .push(MacroProcessorWarning::from_macro_invocation( + macro_name, + args, + format!("{:?} is not a macro", args[0]), + )); + return Ok(String::new()); + }; + let MacroType::Array(array) = macro_body else { + smp.warnings + .push(MacroProcessorWarning::from_macro_invocation( + macro_name, + args, + format!("{:?} is not a macro of type array", args[0]), + )); + return Ok(String::new()); + }; + Ok(array.len().to_string()) +} + #[cfg(feature = "time")] fn smp_builtin_format_time( smp: &mut MacroProcessor, @@ -632,6 +658,10 @@ impl MacroProcessor { String::from("array_each"), MacroType::Function(smp_builtin_array_each), ); + self.define_macro( + String::from("array_size"), + MacroType::Function(smp_builtin_array_size), + ); #[cfg(feature = "time")] self.define_macro( String::from("format_time"), |