ValidateOptions (open)
Validate the options passed to a function
Syntax
// Core function, no LOADLIB necessary
RECORD FUNCTION ValidateOptions(RECORD defaultoptions, RECORD options, RECORD metaoptions)Parameters
RECORD defaultoptionsDefaults, and structure which the options should follow
RECORD optionsPassed in options
RECORD metaoptionsMeta options describing the otpions
discardList of cells to discard if passed
enumsRecord with list of allowed string values for options
notypecheckList of cells whose type does not have to be checked
optionalList of cells which will only exist in the output if they're explicitly set
passthroughPass through any unrecognized options in the output record, instead of failing on them
passthroughinStore any unrecognized options in the specified cell, instead of failing on them
requiredList of cells which must exist in the options record
titleName for the options record used in exceptions after the word 'in'. Defaults to 'options'
Return value
RECORDValidated options, with missing values added
Examples
// Throws if options doesn't contain a cell 'A'.
options := ValidateOptions([ a := 1 ], options, [ required := [ "a" ] ]);
// Returns a record without cell 'A' if options doesn't contain that cell
options := ValidateOptions([ a := 1 ], options, [ optional := [ "a" ] ]);
// Removes cell 'A' from the options
options := ValidateOptions([ a := 1, b := 1 ], options, [ discard := [ "a" ] ]);
// Allow all types for cell 'A' (eg. 0m, "test", DEFAULT OBJECT)
options := ValidateOptions([ a := 1 ], options, [ notypecheck := [ "a" ] ]);
// Restricts cell 'ELEMENT' to the values 'earth', 'water', 'fire' and 'wind'
options := ValidateOptions(
[ element := "wind"
], options,
[ enums := [ element := [ "earth", "water", "fire", "wind" ] ]
]);