Adding the ability to add default property values.

This commit is contained in:
Ad5001 2021-12-29 13:39:39 +01:00
parent a6df4d544b
commit ba000379d7
Signed by: Ad5001
GPG Key ID: EF45F9C6AFE20160
2 changed files with 8 additions and 3 deletions

View File

@ -26,6 +26,10 @@ To declare a property, you can use the `property` function. For example, for an
**NOTE**: Bash doesn't have a typing system, so you cannot set property types.
You can also set default values by adding a property after the declaration, e.g:
property "Example"
Class functions are declared the same way you would in bash, except it uses a prefix with object type. For example:

View File

@ -173,17 +173,18 @@ _accessProperty() {
# Declares a property.
# Signature: (<string propertyFullName>)
# Declares a property with an optional default value.
# Signature: (<string propertyFullName>, [string propertyValue])
property() {
# Split the name by ".". First element is variable name,
# second is property name.
propertyNames=($(echo $propertyFullName | tr "." "\n"))
# Default value
eval "_${varName}_properties[$prop]=''"
eval "_${varName}_properties[$prop]='$propertyValue'"
# Property alias
eval "$propertyFullName() { _accessProperty $varName $prop \$@; }"