Skip to main content

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

Required
MacroField.Type: MacroFieldType

The type of data this field will take (e.g., "number"). See MacroFieldType#Name for the options available!

Name

Required
MacroField.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(valueany) → 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
}
Show raw api
{
    "functions": [
        {
            "name": "Validator",
            "desc": "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`\nreturn a `string` detailing the issue. If everything is OK, return nil.\n\nAn example use case is if we have a `\"number\"` field, but we want to make sure it is non-negative.\n```\n{\n    Name = \"Height\";\n    MacroFieldType = \"number\";\n    Validator = function(someNumber)\n        if someNumber < 0 then\n            return (\"Must be non-negative. Got: %d\"):format(someNumber)\n        end\n    end\n}\n```",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 52,
                "path": "docs_api/sub_definitions.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "Type",
            "desc": "The type of data this field will take (e.g., `\"number\"`). See [MacroFieldType#Name] for the options available!",
            "lua_type": "MacroFieldType",
            "tags": [
                "Required"
            ],
            "source": {
                "line": 14,
                "path": "docs_api/sub_definitions.lua"
            }
        },
        {
            "name": "Name",
            "desc": "The name of this field. This is the same string used to reference this field within a macro.",
            "lua_type": "string",
            "tags": [
                "Required"
            ],
            "source": {
                "line": 22,
                "path": "docs_api/sub_definitions.lua"
            }
        },
        {
            "name": "IsRequired",
            "desc": "If true, the macro will not run + produce a `MacroWarn` in the output if a value has not been defined.",
            "lua_type": "boolean",
            "source": {
                "line": 29,
                "path": "docs_api/sub_definitions.lua"
            }
        }
    ],
    "types": [],
    "name": "MacroField",
    "desc": "This is a datastructure that populates [MacroDefinition#Fields] and defines the different fields that will appear for a macro on the widget.",
    "source": {
        "line": 6,
        "path": "docs_api/sub_definitions.lua"
    }
}