Conditional compilation
module My.Mod
// This line will only import Other.Mod if it exists.
@if(ModuleExists("Other.Mod"))
import Other.Mod.*
// This function has two versions: one for when Other.Mod exists and one for
// when it doesn't.
// The imports from Other.Mod are only valid in the first version, because
// they depend on the condition.
@if(ModuleExists("Other.Mod"))
func Testing() -> Int32 {
return 1;
}
@if(!ModuleExists("Other.Mod"))
func Testing() -> Int32 {
return 2;
}
// This method wrapper/replacement only take effect if Other.Mod doesn't exist.
@if(!ModuleExists("Other.Mod"))
@wrapMethod(PlayerPuppet)
protected cb func OnGameAttached() -> Bool {
Log("I'm in a wrapper");
wrappedMethod();
}
// Class is defined only if Other.Mod exists.
@if(ModuleExists("Other.Mod"))
public class MySettings {
// Same as Testing() above, but for fields of a class.
@if(ModuleExists("Other.Mod"))
let resolution: Vector2;
@if(!ModuleExists("Other.Mod"))
let resolution: String;
// Same as Testing() above, but for methods of a class.
@if(ModuleExists("My.Mod.Test"))
public func GetMode() -> CName {
return n"Debug";
}
@if(!ModuleExists("My.Mod.Test"))
public func GetMode() -> CName {
return n"Release";
}
}Last updated
Was this helpful?