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

main
Ad5001 9 months ago
parent 66bfe1d2c4
commit d4a7290707
Signed by: Ad5001
GPG Key ID: EF45F9C6AFE20160
  1. 3
      example/Example.shn
  2. 6
      example/Static.shc
  3. 29
      example/script.sh

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

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

@ -3,14 +3,31 @@ OOP_ROOT=..
. $OOP_ROOT/oop.sh # Import library.
# Import library
importNamespace Example.shn
Example.Object t1 "Test"
Example.Object t2 "Example"
# OOP Example
Example.Object obj1 "First Object"
Example.Object obj2 "Second Object"
t1.print
t2.print
$obj1.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

Loading…
Cancel
Save