You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The variant type represents a value whose type is not known until further processing is done.
There will be no autocomplete (unless overridden as described in #50), and the user can type any string for an argument of this type.
The command implementation will receive an instance of a new Variant class in the slot of the argument.
The Variant class will have methods to further process the data with one of the built-in Cmdr data types.
RawValue: string, the input text. Parse(type: string | string[]): string | false, string, parses a value Match(arms: MatchArm[]): any Performs pattern matching
Parse
localparsedType, value=variant:Parse("number")
parsedType is "number" if the parsing was successful, and value is of the parsed type. parsedType is alternatively false, in which case value will be a string containing the error.
Parse could also receive an array of type names, in which case it attempts to parse down the line until it finds one that is not invalid. For example:
In this case, the input 1 will return "number", 1, and the input text will return false, "Not a valid boolean or whatever the error message is"
Match
Match accepts an array of matches. Each potential match is an array with two values. The first value is a Lua string pattern. The second is a function, which will receive all captures from the pattern. String patterns which do not match are skipped. Matches are tested in order. The function should return the final value that will be the result from the Match call.
Optionally return a type name as the second return value to have Cmdr run the first return value through that type's parser before continuing. If this parsing fails, then that pattern match is considered failed and Match will continue to move down the array.
Match returns nil if no matches are found.
The text was updated successfully, but these errors were encountered:
The
variant
type represents a value whose type is not known until further processing is done.There will be no autocomplete (unless overridden as described in #50), and the user can type any string for an argument of this type.
The command implementation will receive an instance of a new
Variant
class in the slot of the argument.The
Variant
class will have methods to further process the data with one of the built-in Cmdr data types.RawValue: string
, the input text.Parse(type: string | string[]): string | false, string
, parses a valueMatch(arms: MatchArm[]): any
Performs pattern matchingParse
parsedType
is"number"
if the parsing was successful, andvalue
is of the parsed type.parsedType
is alternativelyfalse
, in which casevalue
will be a string containing the error.Parse
could also receive an array of type names, in which case it attempts to parse down the line until it finds one that is not invalid. For example:In this case, the input
1
will return"number", 1
, and the inputtext
will returnfalse, "Not a valid boolean or whatever the error message is"
Match
Match
accepts an array of matches. Each potential match is an array with two values. The first value is a Lua string pattern. The second is a function, which will receive all captures from the pattern. String patterns which do not match are skipped. Matches are tested in order. The function should return the final value that will be the result from theMatch
call.Optionally return a type name as the second return value to have Cmdr run the first return value through that type's parser before continuing. If this parsing fails, then that pattern match is considered failed and Match will continue to move down the array.
Match
returns nil if no matches are found.The text was updated successfully, but these errors were encountered: