This code show how macro works :
Code: Select all
Macro CEI
CompilerElseIf #True
EndMacro
Macro TestCompilerElseIf
CompilerIf #False
; Nothing
CEI ; In macro CEI is replaced before "execute" CompilerIf. So firsh #FOO is choosed
#FOO = "FOO defined in macro"
CompilerElse
#FOO = "FOO defined in normal code"
CompilerEndIf
EndMacro
; The same bloc of code as the one inside macro "TestCompilerElseIf"
CompilerIf #False
; Nothing
CEI ; Outside macro CompilerIf is executed Before (because it's on another line). So the macro is never replaced.
#FOO = "FOO defined in macro"
CompilerElse
#FOO = "FOO defined in normal code"
CompilerEndIf
TestCompilerElseIf ; Constant already declared with a different value: #FOO
Code: Select all
Macro DQ
"
EndMacro
Macro Recursive(DEEP)
CompilerWarning DQ#DEEP passes restantes"
CompilerSelect DEEP
CompilerCase 1
CompilerWarning "Dernière passe"
CompilerCase 2
Recursive(1)
CompilerEndSelect
EndMacro
Recursive(2)
Code: Select all
EnableExplicit ; This is concept code. It does NOT works without lot patchs and some preprocessor changes.
Macro SetMacroVar(MacroVar, Value)
UndefineMacro MacroVar
Macro MacroVar
Value
EndMacro
EndMacro
Macro AddMacroVar(MacroVar, Value)
SetMacro(MacroVar, (MacroVar) + (Value))
EndMacro
Macro Normalize(MacroVar, Value)
CompilerSelect Value
CompilerCase 0
SetMacroVar(MacroVar, 0)
CompilerCase 1
SetMacroVar(MacroVar, 1)
CompilerCase 2
SetMacroVar(MacroVar, 2)
CompilerCase 3
SetMacroVar(MacroVar, 3)
; And so on
CompilerEndSelect
EndMacro
SetMacroVar(FOO, 1)
AddMacroVar(FOO, 2)
CompilerWarning "FOO" ; Display "3"