Jump to content

Class syntax in AutoIt


Recommended Posts

I've made a transpiler for converting AutoIt-like class syntax into AutoIt code.

GIthub: https://github.com/genius257/au3class/

Example for the syntax:

#include-once

Class Example
    $property = Null

    Func __construct($ts = 'now')
        $this.property = 0
    EndFunc

    Func __destruct()
        ; Destructor code here.
    EndFunc

    Func method()
        Return "something"
    EndFunc

    Get Func dynamic()
        Return $this.dynamic & $this.property
    EndFunc

    Set Func dynamic($value)
        $this.property += 1
        $this.dynamic = $value
    EndFunc
EndClass

$oExample = Example()

$oExample.dynamic = 12

MsgBox(0, "", $oExample.dynamic)

MsgBox(0, "", $oExample.method())

$oExample = Null
  • class properties are defined as variables within the Class structure
  • class methods are defined as function declarations within the Class structure
  • property getters and setters need to have Get or Set in front of their function declaration
    • Getter and setter can access their own underlying property, without triggering the getter or setter for said variable.

Version 2 produces more code than version 1, but does not need any other scripts included to work.

Version 2 is also faster than version 1, since version 2 creates specific code for looking up class members, instead of relying on AutoItObject_Internal with it's dynamic properties lookup.

See the example folder on Github for building and using this: https://github.com/genius257/au3class/tree/master/Example

 

Link to comment
Share on other sites

Hi @genius257

Just a small oversight: I tried to "build" example.au3 from example.au3p using build.au3
the output file produced contains this little "flaw":

If $pObj=0 Then Return $__AOI_E_POINTER
"C:\Temp\au3class-master\Example\Example.au3"(30,40) : warning: $__AOI_E_POINTER: possibly used before declaration.
If $pObj=0 Then Return $__AOI_E_POINTER
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Temp\au3class-master\Example\Example.au3"(30,40) : error: $__AOI_E_POINTER: undeclared global variable.
If $pObj=0 Then Return $__AOI_E_POINTER
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

apart from this the created "object" works correctly.

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Hi @Gianni :)

You are right, that is indeed an oversight, thanks for telling me ;)

The issue has been fixed on the master branch now, but I'll wait a day or two before creating a new release, to verify no more small mistakes appear :D

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...