- MacroParam(): Tests if a parameter is set (see discussion here for something that doesn't work with strings).
- MacroIf: Macros are processed with highest priority so to control its behavior even CompilerIf won't work. However in certain cases this is necessary, e.g. to be able to simulate a return type (see example below).
The context is that I'm desperately trying to make something like the following work (and in the past I came across variations several times). Unfortunately there are a couple of problems:
Code: Select all
Macro _Quote
"
EndMacro
Macro _MacroParam(parameter=)
Bool(_Quote parameter _Quote <> " ") ; Not working if parameter is a string. :(
EndMacro
Macro Test(String, Character=)
CompilerIf _MacroParam(Character)
Trim(String, Character)
CompilerElse
Trim(String)
CompilerEndIf
EndMacro
result$ = Test("-abc-", "-") ; Problem with "CompilerIf". :(
result$ = Test(" abc ") ; Proper handling of optional parameter is tricky. :(

Code: Select all
Macro Test(String, Character=)
MacroIf MacroParam(Character)
Trim(String, Character)
MacroElse
Trim(String)
MacroEndIf
EndMacro
result$ = Test("-abc-", "-") ; Works fine.
result$ = Test(" abc ") ; Amazing, this truly is the future! :)