"using" directive, static classes, proper examples, declared objects are nom recommanded to be accessed using the $ prefix like all other variables.

This commit is contained in:
Adsooi 2021-12-28 20:58:07 +01:00
parent 66bfe1d2c4
commit d4a7290707
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
3 changed files with 32 additions and 6 deletions

View file

@ -5,3 +5,6 @@ namespace Example
# Object declaration, from class name to file name. # Object declaration, from class name to file name.
class Object "Object.shc" class Object "Object.shc"
# Static class declaration
static_class Static "Static.shc"

6
example/Static.shc Normal file
View file

@ -0,0 +1,6 @@
# Function declaration.
# NOTE: Properties can't be declared for static classes
Static.print() {
echo "$@"
}

View file

@ -3,14 +3,31 @@ OOP_ROOT=..
. $OOP_ROOT/oop.sh # Import library. . $OOP_ROOT/oop.sh # Import library.
# Import library
importNamespace Example.shn importNamespace Example.shn
Example.Object t1 "Test" # OOP Example
Example.Object t2 "Example" Example.Object obj1 "First Object"
Example.Object obj2 "Second Object"
t1.print $obj1.print
t2.print # The $ is not mandatory, but is recommanded.
obj2.print
t1.name = "New name" objs=($obj1 $obj2)
${objs[0]}.print
${objs[1]}.print
t1.print $obj1.name = "New name"
$obj1.print
# Static example
Example.Static.print "Example text"
# Using directive.
using Example
Object usingObj "New"
$usingObj.print