MacroField
This is a datastructure that populates MacroDefinition#Fields and defines the different fields that will appear for a macro on the widget.
Properties
Type
RequiredMacroField.Type:
MacroFieldType
The type of data this field will take (e.g., "number"
). See MacroFieldType#Name for the options available!
Name
RequiredMacroField.Name:
string
The name of this field. This is the same string used to reference this field within a macro.
IsRequired
MacroField.IsRequired:
boolean
If true, the macro will not run + produce a MacroWarn
in the output if a value has not been defined.
Functions
Validator
MacroField.
Validator
(
value:
any
) →
string
We can define a Validator
function to run our field value by when we run the macro. If there is an issue, we have Validator
return a string
detailing the issue. If everything is OK, return nil.
An example use case is if we have a "number"
field, but we want to make sure it is non-negative.
{
Name = "Height";
MacroFieldType = "number";
Validator = function(someNumber)
if someNumber < 0 then
return ("Must be non-negative. Got: %d"):format(someNumber)
end
end
}