This keyword is used to make debugging easier while testing parts of code
Everything after #DEBUG will not be parsed by TeenyScript and not included from other files
Both forward/ and backwardslashes\ are accepted, but later translated to backslashes \
Directory-popping \ and \\ works with the recursive include tags *.ts and **.ts
; Include another .ts file
#include <file.ts>
; Regular .au3 files are just parsed as they are
#include <file.au3>
; Include a whole subdirectory
#include <directory\*.ts>
; Include a whole subdirectory recursively
#include <directory\**.ts>
; ~ Include from parent \ script directory
; Lets say you have the folder "c:\autoit\" that has this file structure:
; \Main.ts.au3 c:\autoit\main.ts.au3
; \sub\Somethingelse.ts.au3 c:\autoit\sub\somethingelse.ts.au3
; \sub\Deeper\Somethingelse.ts.au3 c:\autoit\sub\Deeper\somethingelse.ts.au3
; Make belive \Main.ts.au3 looks like this:
#include <sub\Somethingelse.ts.au3>
; And \sub\Somethingelse.ts.au3 looks like this:
#include <\sub\deeper\Somethingelse.ts>
; When you start Main.ts.au3, TS will include "c:\autoit\sub\somethingelse.ts.au3" first, then from that file, TS will include "c:\autoit\sub\Deeper\somethingelse.ts.au3"
@Extends
Extends another class
May not be nested
; An extension acts almost like a class, but it will never return the class object (And no parameters may be passed either)
$myExtension = Func(Extension)
@Public $public_method = Func()
; Prompt something
MsgBox(0,0, $this.name)
EndFunc
EndFunc
$MyClass = Func(Class)
@Public $this.name = "TarreTarreTarre"
; Inherit everything from the extension
@Extends $myExtension
EndFunc
$Main = Func()
Local $Example = $MyClass()
; Call some method from the class Object
$Example.public_method()
EndFunc()
@MethodName
Retrives the Methods name
Syntax
@MethodName
Return (Success)
The name of the method as a STRING (Without namespaces)
Return (Failure)
Unkown macro au3 error
This macro only works within .ts files
$Example_one = Func()
MsgBox(0, "", "The name of this method is: " & @MethodName)
EndFunc()
@MethodParams
Retrives the parameters
Syntax
@MethodParams
Return (Success)
The method parameters as a STRING (Without namespaces)
Return (Failure)
Unkown macro au3 error
This macro only works within .ts files
$Example_one = Func($name, $lastname = "doe")
MsgBox(0, "", "The params of this method is: " & @MethodParams)
EndFunc("TarreTarreTarre")
@Namespace (Get)
Retrive the current Namespace
Syntax
@Namespace
Return (Success)
The actual name of the given namespace with forward slashes
Return (Failure)
Empty string
-
@Namespace Mynamespace
$MyFunc = Func()
MsgBox(0,0, "We are in the namespace: " & @Namespace)
EndFunc
$Main = Func()
Mynamespace/$MyFunc()
EndFunc()
@Namespace (Set)
Assign a file with a namespace
@Namespace Name/Space
$MyFunc = Func()
MsgBox(0,0,"Hello!")
EndFunc
$Main = Func()
; every global-scoped variable can only be accesed through the namespace of the current file
Name/Space/$MyFunc()
; This will throw an error (Try and uncomment the code below)
;$MyFunc()
EndFunc()
@Public, @Private, @Readonly
Access scope
Methods can only use @Private and @Public
Properties can use all three
$MyClass = Func(Class)
; Can be accesed but not changed
@Readonly $this.book = "This can only be read"
; Can be accesed and changed anywhere
@Public $this.age = 27
; Can be accesed and changed within the class only
@Private $this.name = "TarreTarreTarre"
; This is a public method
; Can be accesed anywhere
$getName = Func()
Return $this.name
EndFunc
; This is also a public method
; Can be accesed anywhere
@Public $getBook = Func()
Return $this.book
EndFunc
; Private method
; Can be accesed within the class only
@Private $setName = Func($sName)
EndFunc
EndFunc(); instansiate the class upon creation
$Main = Func()
; Acces the public variable (note, no method)
MsgBox(0, "Example 1", "Access public property")
ConsoleWrite("$this.age = " & $MyClass.age & @CRLF)
; # # # # Readonly example
; This will cause an COM error
MsgBox(0, "Example 2", "Attempt to change Readonly property")
$MyClass.book = "Chaning the book"
; # # # # # Private example
; This will cause an "unkown name" COM error since the property is private
MsgBox(0, "Example 3", "Access private method")
ConsoleWrite("$MyClass.name = " & $MyClass.name & @CRLF)
; This will display the value since we are getting the private property -
; thru an public method
MsgBox(0, "Example 4", "Access public method which contains private properties")
ConsoleWrite("$MyClass.getName() = " & $MyClass.getName() & @CRLF)
EndFunc()
@Use
Namespace alias inside TS functions and methods
Syntax
@Use x AS Y
Return (Success)
Actual Variable-function
Return (Failure)
Au3 Error "Unkown function ..."
Aliases may only be [a-z]+
@Use is unique for each super parent
@Namespace hello/this/namespace/is/long
$MyClass = Func(Class)
$method = Func()
MsgBox(0,0,"This is the namespace we are in at: "&@Namespace)
EndFunc
EndFunc
$Main = Func()
;Assign our alias
@Use hello/this/namespace/is/long AT short
; Call the class with our alias
short/$MyClass().method()
; Call directly from global namespace
hello/this/namespace/is/long/$MyClass().method()
EndFunc()
Closure Func ... (EndFunc)
Autoit function Closures
Syntax
Func() ..... (EndFunc)
Return (Success)
A closure
Closures can be used everywhere.
; Our helper method
$isCallable = Func($unk)
Local $bIsCallable = False
if FuncName($unk) Or IsFunc($unk) Then $bIsCallable = True
; Now we call the callable function
$unk()
Return $bIsCallable
EndFunc
$Main = Func()
; Regular function
$function_a = Func()
MsgBox(0, "", "hello from "&@MethodName)
EndFunc
; Check to see if $function_a is a function
If $isCallable($function_a) Then
MsgBox(0, "", "$function_a is a Callable function")
Else
MsgBox(0, "", "$function_a is _NOT_ a Callable function")
EndIf
; Now we do the same with a closure
If $isCallable(Func()
;Some function we passing as a parameter
MsgBox(0,0,"Hello from unkown name")
(EndFunc)) Then
MsgBox(0, "", "This is a Callable function")
Else
MsgBox(0, "", "This is _NOT_ a Callable function")
EndIf
EndFunc()
Func(Class)
Create a Class
No protected methods exists in AutoitObject, so we cannot have that either..
#include <Array.au3>
$MyClass = Func(class)
@Private $this.name = "TarreTarreTarre"
;Public class
$method_a = Func()
MsgBox(0, "", "Hello!")
EndFunc
;Private class (Can only be called within this class)
@Private $method_b = Func($a,$b, $c)
EndFunc
EndFunc
#DEBUG
; Retrive properties from the class
Local $UseClass = $MyClass()
; Display methods of this class
Local $aMethods = $UseClass.__Methods__
_ArrayDisplay($aMethods)
; Display properties of this class
Local $aProps = $UseClass.__Properties__
_ArrayDisplay($aProps)
;Display the current namespace (if any)
MsgBox(0, "", $UseClass.__Namespace__)
; Display the actual name of the class
MsgBox(0, "", $UseClass.__cName__)
Func(Construct)
Create a constructor for a TS class
Parameters (If any) will be inherited from the parent class, if parameters are declared an TS_Compose_methods error will occur
By default the Construct method always Returns $this but that can be overwritten by just adding a Return statement at the end of the function
The construct may only be assigned Publicly since it will be called outside the class
$MyClass = Func(Class, $a, $b)
@Private $this.__a = Null
@Private $this.__b = Null
$MyConstructor = Func(Construct)
$this.__a = $a
$this.__b = $b
ConsoleWrite(@MethodName & @CRLF)
EndFunc
@Public $ShowData = Func()
MsgBox(0,0,(<<<)
"__a: {$this.__a}."
"__b: {$this.__b}."
(>>>))
Return $this
EndFunc
EndFunc
$Main = Func()
; Init class (will also run MyConstructor)
Local $Example = $MyClass(25,30)
; Will display:
; __a: 25
; __b: 30
$Example.ShowData()
; Call the constructor by its method name (No need to init the class again)
$Example.MyConstructor(55, 65)
; Will display:
; __a: 55
; __b: 65
$Example.ShowData()
EndFunc()
Func(Extension)
Create a extension class for multiple usage (DRY)
; An extension acts almost like a class, but it will never return the class object (And no parameters may be passed either)
$ParentClass = Func(Extension)
@Private $this.secret_number = 1234567
@Readonly $this.protected_name = "TarreTarreTarre"
@Public $public_method = Func()
MsgBox(0, "Hello", (<<<)
"Called method: " & @MethodName
"secret_number = {$this.secret_number}"
(>>>))
$this.private_method()
EndFunc
EndFunc
$MyClass = Func(Class)
; Extend the Extension
@Extends $ParentClass
@Private $private_method = Func()
ConsoleWrite("Im called private!" & @CRLF)
EndFunc
EndFunc
$Main = Func()
Local $Example = $MyClass()
; Call some method from the class Object
$Example.public_method()
EndFunc()
Heredoc (<<<) ... (>>>)
Heredoc
$Main = Func()
$MyVar = "My first var"
$MySecondVar = "My Second Var"
$MyText = (<<<)
"First line"
"Second line"
""
"$MyVar = {$MyVar}"
"$MySecondVar = " & $MySecondVar
"@IpAdress1 = {@IPAddress1}"
"@Computername = " & @ComputerName
(>>>)
; Display mytext
MsgBox(0, "Example 1", $MyText)
; You can also pass Heredocs as parameters to functions
MsgBox(0, "Example 2", (<<<)
"My messagebox"
""
"Hello!"
(>>>))
EndFunc()
Lists { }
Lists
When using $list{$Key} TS will parse it as Execute("$list." & $key) but if you are using $list{"key"} TS will parse it as $list.key
List keys may only contain a-z, 0-9 and _
List keys cannot contain dots/periods.
;Basic List usage
$Example_A = Func()
;Create MyList with 1 key and value
Local $myList = {
'Name': 'Tarre'
}
;Append more data \ Change previous data on $MyList
$myList{'Age'} = 25
;Create MySecondList with 2 keys and values
Local $MySecondList = {
"Name" => "John",
"Age" => "00"
}
;Use a variable instead of raw text
Local $KeyName = "Age"
Local $KeyVal = 1337
$MySecondList{$KeyName} = $KeyVal
; Yes, you can do this also
Local $oList = {'myList': $myList, 'mySecondList' => $MySecondList}
;Return both our objects
Return $oList
EndFunc();call the function on the variable
; Loop through list and print their values
$Example_B = Func()
Local $MyList = {'A': 'Hello FROM A', 'B': 'Hello FROM B', 'C': 'Hello FROM C'}; Create a empty list
Local $aNames = ['A', 'B', 'C']
For $i = 0 To UBound($aNames) -1
MsgBox(0,0,$myList{$aNames[$i]})
Next
EndFunc
#DEBUG
MsgBox(0,"Example A 1", $Example_A.myList.Name)
MsgBox(0,"Example A 2", $Example_A.myList.Age)
MsgBox(0,"Example A 3", $Example_A.mySecondList.Name)
MsgBox(0,"Example A 4", $Example_A.mySecondList.Age)
$Example_B(); Execute examble B
_TS_ErrorNotify
Com error settings for your script
Syntax
_TS_ErrorNotify($c)
Return (Success)
Last option used
Return (Failure)
-
The avilable constants are: $_TS_IGNORE, $_TS_CONSOLE and $_TS_MSGBOX
Default option for non-compiled scripts is $_TS_CONSOLE and for compiled (exe) scripts is $_TS_MSGBOX
; Ignore all com errors
$_TS_ErrorNotify = _TS_ErrorNotify($_TS_IGNORE)
Local $NotAcomObject = null
$NotAcomObject.test = 25
if @error then MsgBox(0, "Triggered", "Com error!!!")
; // Restore error reporting
_TS_ErrorNotify($_TS_ErrorNotify)